var MUSIC_CLICK_BTN: string = "click_mp3";//按钮
var MUSIC_HIT: string = "hit_mp3";
var MUSIC_ADDNUM: string = "addNum_mp3";
var MUSIC_FIRE: string = "fire_mp3";//发射
var MUSIC_FLOOR: string = "floor_mp3";
var MUSIC_BG: string = "background_mp3";//背景
var MUSIC_CL: string = "ct_mp3";//激光
var MUSIC_BaoZha: string = "Baozha_mp3";//爆炸
var MUSIC_Jinbi: string = "Jinbi_mp3";//金币
var MUSIC_Eatdaoju: string = "EatDaoju_mp3";//金币
var tishi: number = 9;
var tanChuang:number=0;


var EVENT_FIRE: string = "event fire";
var EVENT_REMOVE: string = "event remove";
var TYPE_HAND: string = "type hand";
var ICON_ADD: string = "addIcon_png"
var SHAPE = { rect: "rect", circle: "circle" }//形状
var OVER_DIS: number = 200;

enum lizitexiao {
    " ",
    "ball_png",//基础球
    "chu_png",//触发球
    "purpleBall_png",//放大球
    "zhong_png",//重力球
    "redball2_png",//爆炸球
}

class GameControl extends moon.BasicGamePanel {
    private tishi2: number = 0;
    private gameHandle;
    private closeBtn: MImage;
    private isdisplay = false;
    private bitmap: egret.Bitmap;
    private rankingListMask: egret.Shape;
    public static GameControlSole: GameControl
    public isChanger: number = 0;
    public shareNum: number = 0;
    /**死亡时变量 */
    public overValue: number = 0;
    public isOver: number = 0;
    public isStrike: number;
    public bianliang;
    private boomNum: number = 0;
    /**与球触碰的线 */
    private shape1: egret.Shape = new egret.Shape();
    /**储存场景所有静止的子弹 */
    public my_ball: any[] = [];
    public my_strikeBall: any[] = [];
    public my_peng: any[] = [];
    public my_chuchun: any[] = [];//储存子弹
    public my_chuchun2: any = [];
    /**未与球触碰的线 */
    private g_un:any;
    private shape: egret.Shape = new egret.Shape();
    private world: P2World;//2D物理世界
    private material: p2.Material;//碰撞时的弹性变化
    private names: string[] = [];//数字刚体皮肤名字
    private gun: Gun;//炮
    private guntop:GunTop//上方炮
    private Share: shareButton;//分享按钮
    public Collidetime: collideTime;//碰撞次数显示
    public Striketime: strikeTime//108球显示
    public propCount: number = 0;//反弹后获得道具数量
    private controlGun: control.ControlBasic;//控制炮的方向
    private vec: egret.Point;//发炮时的冲量值
    private removeSkins: any[] = [];//需要删除刚体的皮肤
    private container: Sprite;//数字刚体皮肤容器
    private moveNum: number = 0;//数字刚体可移动次数
    private ballNum: number = 0;//发球数量
    private minBodyCount: number = 1;//数字刚体的最少数值
    private rr: number//半径
    private zhuobiao: any = null//坐标
    private fashezhuo: any = null
    private panshu: number = 0//第一次运行
    private playpd: Boolean = false//齿轮音
    private falsekou: any//子弹出口
    /**限制数 */
    public restrictNumber: number = 0;
    /**子弹 */
    private Bulebullet:any;
    private fakeBullet: any;
    private boomBullet: any;
    private MagnifyBullet: any;
    public NowBullet: any;
    public NowBullet1: any = null;
    private gravityBullet: any;
    private strikeBullet: any;
    private time: number = 0;
    /**线发光控制按钮*/
    private fenxiang: Boolean = true;
    private faguang: Boolean = false;
    private glowFilter: egret.GlowFilter;
    private e: number = 13;//距离
    private faan: any//微调按钮
    private xiaofaan: any;
    private xiaoluntop:any;//上方小轮
    private fashe: any;//
    private adjustment: any//微调按钮
    //private fakeBulletPoint: egret.Point;
    public bei: any;
    public isFire: boolean = false;
    public shu11: number = 0;//计数
    public sffaqiu: boolean = false;
    /**分数 */
    public count: number = 0;
    /**道具 */
    public m_PropManager: py2Obj.PropManager = null;//普通加分
    public OverTimer: egret.Timer;
    public gravityTime: egret.Timer;
    public jiguang: egret.Timer;
    public Ball: MImage;

    public yinxiaoBool: boolean = false;
    /**发射按钮的点击按键 */
    private fashe2: Boolean = false;//发射按钮
    public jiaQiuCount: number = 0;
    public qiehuan: Boolean;

    /**选关界面背景*/
    private bj: MImage;
    /**选关界面开始按钮*/
    private btn: MButton;
    /**关卡数字*/
    public upgradeNumber: number = 1;
    public upgradeNumber2: number = 0;
    public upgradeNumber3: number = 0;
    public upgradeNumber4: number = 0;
    public jinbicishu: number = 0;
    public daojucishu: number = 0;

    public daojutishi: number = 0;
    public baozha: MImage;//预存爆炸球道具
    public zhongli: MImage;//预存重力球道具
    public fangda: MImage;//预存放大球道具
    public chufa: MImage;//预存触发球道具
    public Textbaozha: TextField;
    public Textchufa: TextField;
    public Textzhongli: TextField;
    public Textfangda: TextField;
    public BaozhaCount: number = 0;
    public ChufaCount: number = 0;
    public ZhongliCount: number = 0;
    public FangdaCount: number = 0;
    public Weitiaojuli: number = 0;//微调距离
    /**回合计数 */
    public huiheNum:number=0;
    /**回合判断 */
    public istop:Boolean=false;

    /**新手指导 */
    private Newarrow: MImage;//发射按钮的指示箭头
    private Newarrow1: MImage;////发射按钮的指示箭头
    private Newjiantou: MImage;//指示道具的按钮

	public static account: string;//登录用户
//玩家
    public playOne:py2Obj.qiu;
    public playTwo:py2Obj.qiu;
    public playOneHpTXT:TextField;
    public playTwoHpTXT:TextField;
    public playOneHp:number=5;
    public playTwoHp:number=5;
//砖
    public zhuan:py2Obj.zhuanWall;
    public zhuanTop:py2Obj.zhuanWall;
    public zhuanTXT:TextField;
    public zhuanTopTXT:TextField;
    // private Newbj: MImage;//背景
    // private NewText: TextField//发射按钮文字
    /**当前子弹 */
   public nowBulletImg:MImage;
   public nowBulletImgBule:MImage;
    /**加分显示分本数字*/
    public shuzishuzi: number = 0;
    protected render(): void {
        super.render();

        // GameData.stageHeight = this.stageHeight;
        // GameData.stageWidth = this.stageWidth;
        // SoundControl.getIns().addItem(MUSIC_HIT);
        // SoundControl.getIns().addItem(MUSIC_ADDNUM);
        // SoundControl.getIns().addItem(MUSIC_FIRE);
        // SoundControl.getIns().addItem(MUSIC_FLOOR);
        // SoundControl.getIns().addItem(MUSIC_BG, true);
        // SoundControl.getIns().play(MUSIC_BG, 0, 9999);
        // platform.findShareQuery(this.shengyin);


        this.createImageBg("BG_png");
        var time1 = new egret.Timer(500, 0);
        // time1.start();
        time1.addEventListener(egret.TimerEvent.TIMER, this.playcl1, this);

        /**发射按钮*/
        this.fashe = new MImage("小轮_png");
        this.addChild(this.fashe);
        this.fashe.x = 500;
        this.fashe.y = 900;
        this.fashe.scaleX = 0.5;
        this.fashe.scaleY = 0.5;
        /**当前子弹图片 */
        this.nowBulletImg=new MImage("ball_png");
        this.addChild(this.nowBulletImg);
        this.nowBulletImg.x = 505;
        this.nowBulletImg.y = 905;
        this.nowBulletImgBule=new MImage("purpleBall_png");
        this.addChild(this.nowBulletImgBule);
        this.nowBulletImgBule.x = 505;
        this.nowBulletImgBule.y = 905;
         this.nowBulletImgBule.visible=false;
        /*微调按钮*///改为切换子弹按钮
        this.adjustment = new MImage("小轮_png");
        this.addChild(this.adjustment);
        this.adjustment.x = 500;
        this.adjustment.y = 1000;
        this.adjustment.scaleX = 0.5;
        this.adjustment.scaleY = 0.5;
        this.adjustment.touchEnabled = true;
        //egret.Tween.get(this.adjustment,{loop:true}).to({alpha:0},300).to({alpha:1},300);

        /** */
        /**新手指导 */
        this.Newarrow = new MImage("arrow_png");//发射按钮的指示箭头
        // this.addChild(this.Newarrow);
        this.Newarrow.x = 440;
        this.Newarrow.y = 790;
        this.Newarrow.scaleX = 0.5;
        this.Newarrow.scaleY = 1;
        this.Newarrow.rotation = -35;

        this.Newarrow1 = new MImage("arrow_png");//微调按钮的指示箭头
        //  this.addChild(this.Newarrow1);
        this.upgradeNumber4 = 1;//新手引导
        this.Newarrow1.x = 400;
        this.Newarrow1.y = 1150;
        this.Newarrow1.scaleX = 0.5;
        this.Newarrow1.scaleY = 1;
        this.Newarrow1.rotation = 250;

        this.Newjiantou = new MImage("jiantou_png");
        // this.Newjiantou.x = 500;
        // this.Newjiantou.y = 500;
        this.Newjiantou.scaleX = 0.3;
        this.Newjiantou.scaleY = 0.3;
        // this.addChild(this.Newjiantou);


        this.addChild(this.Newarrow1);
        this.addChild(this.Newarrow);
        this.Newarrow.visible = false;
        this.Newarrow1.visible = false;
        //  egret.Tween.get(this.Newarrow1, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁

        // egret.localStorage.setItem("xinshouyindao", "false");//新手指导微信存储

        // console.log("是水电费不回去服务收费" + egret.localStorage.getItem("xinshouyindao"));
        //this.Newarrow1.visible = true;
        //  if (tishi == 0 && egret.localStorage.getItem("xinshouyindao") == "false") {
        //  if (egret.localStorage.getItem("xinshouyindao") == "false") {
        if (tishi < 9) {
            this.upgradeNumber2 = 100;
            //    if (egret.localStorage.getItem("xinshouyindao") == "false") {
            this.UpgradeTishi();
        }
        //  if (egret.localStorage.getItem("xinshouyindao") == "true") {
        else {
            this.removeChild(this.Newarrow);
            this.removeChild(this.Newarrow1);
            //  this.bulletMax = 10;
            tishi = 9;//不走新手引导
        }

        /**新手指导 存取数据 */
        // if (egret.localStorage.getItem("xinshouyindao") == "true") {
        //     this.removeChild(this.Newarrow);
        //     this.removeChild(this.Newarrow1);
        // }
        //  }
        //    else
        //    {
        //        return ;
        //    }
        // var bj = new MImage("startPanel1_png");
        // this.bj = bj;
        // var btn: MButton = new MButton(new MImage("jixu_png"), new MImage("jixu_png"));
        // this.btn = btn;
        // btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
        // btn.x = (this.stageWidth - btn.width) >> 1;
        // btn.y = 650;
        // var upgradeText: egret.TextField = new egret.TextField();
        // upgradeText.width = 400;
        // upgradeText.height = 400;
        // upgradeText.x = 140;
        // upgradeText.y = 400;
        // upgradeText.textColor = 0x00c4a851;
        // upgradeText.size = 32;
        // upgradeText.textAlign = egret.HorizontalAlign.CENTER;
        // this.upgradeNumber3 = 1;//防止弹出界面同时出现
        // upgradeText.text = "点击发射按钮"
        // bj.addChild(upgradeText);
        // this.addChild(this.bj);
        // this.addChild(this.fashe);//新手引导
        // // this.Newarrow.visible = true;
        // this.Newarrow1.visible = false;
        // //egret.Tween.get(this.Newarrow,{loop:true}).to({ alpha: 0}, 200).to({ alpha: 1}, 200); //颜色闪烁    
        // //egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
        // // Tween.get(this.Newarrow).to({alpha:1},500);

        //微调轮盘
        this.faan = new MImage("大轮1_png");
        this.addChild(this.faan)
        this.faan.anchorOffsetX = this.faan.width >> 1;
        this.faan.anchorOffsetY = this.faan.height >> 1;
        this.faan.x = 320;
        this.faan.y = 880;
        this.faan.scaleX = 1.2;
        this.faan.scaleY = 1.2;
        this.xiaofaan = new MImage("小轮_png");
        this.addChild(this.xiaofaan)
        this.xiaofaan.anchorOffsetX = this.xiaofaan.width >> 1;
        this.xiaofaan.anchorOffsetY = this.xiaofaan.height >> 1;
        this.xiaofaan.x = 320;
        this.xiaofaan.y = 950;
        this.xiaofaan.scaleY=0.5;
        this.xiaofaan.scaleX=0.5;
        this.xiaoluntop=new MImage("小轮_png");
        this.addChild(this.xiaoluntop);
        this.xiaoluntop.anchorOffsetX = this.xiaoluntop.width >> 1;
        this.xiaoluntop.anchorOffsetY = this.xiaoluntop.height >> 1;
        this.xiaoluntop.x=320;
        this.xiaoluntop.y=130;
        this.xiaoluntop.scaleY=0.5;
        this.xiaoluntop.scaleX=0.5;


        
        

        
        //触发球 
        this.chufa = new MImage("chu_png")
        this.addChild(this.chufa)
        this.chufa.anchorOffsetX = this.chufa.width >> 1;
        this.chufa.anchorOffsetY = this.chufa.height >> 1;
        this.chufa.x = 210;
        this.chufa.y = 1010;
        this.Textchufa = this.createText(0, 0, "0");
        this.Textchufa.textColor = 0x000000;
        this.Textchufa.size = 30;
        this.Textchufa.x = this.chufa.x - 7;
        this.Textchufa.y = this.chufa.y - 14;
        this.chufa.touchEnabled = true;
        this.chufa.addEventListener(egret.TouchEvent.TOUCH_TAP, this.ChufaClick, this);
        //放大球
        this.fangda = new MImage("purpleBall_png")
        this.addChild(this.fangda)
        this.fangda.anchorOffsetX = this.fangda.width >> 1;
        this.fangda.anchorOffsetY = this.fangda.height >> 1;
        this.fangda.x = 280;
        this.fangda.y = 1010;
        this.fangda.scaleX = 1.5;
        this.fangda.scaleY = 1.5;
        this.Textfangda = this.createText(0, 0, "0");
        this.Textfangda.textColor = 0x000000;
        this.Textfangda.size = 30;
        this.Textfangda.x = this.fangda.x - 7;
        this.Textfangda.y = this.fangda.y - 14;
        this.fangda.touchEnabled = true;
        this.fangda.addEventListener(egret.TouchEvent.TOUCH_TAP, this.FangdaClick, this);
        //重力球 
        this.zhongli = new MImage("zhong_png")
        this.addChild(this.zhongli)
        this.zhongli.anchorOffsetX = this.zhongli.width >> 1;
        this.zhongli.anchorOffsetY = this.zhongli.height >> 1;
        this.zhongli.x = 350;
        this.zhongli.y = 1010;
        this.Textzhongli = this.createText(0, 0, "0");
        this.Textzhongli.textColor = 0x000000;
        this.Textzhongli.size = 30;
        this.Textzhongli.x = this.zhongli.x - 7;
        this.Textzhongli.y = this.zhongli.y - 14;
        this.zhongli.touchEnabled = true;
        this.zhongli.addEventListener(egret.TouchEvent.TOUCH_TAP, this.ZhongliClick, this);
        //爆炸球 
        this.baozha = new MImage("redball2_png")
        this.addChild(this.baozha)
        this.baozha.anchorOffsetX = this.baozha.width >> 1;
        this.baozha.anchorOffsetY = this.baozha.height >> 1;
        this.baozha.x = 420;
        this.baozha.y = 1010;
        this.baozha.scaleX = 1.5;
        this.baozha.scaleY = 1.5;
        this.Textbaozha = this.createText(0, 0, "0");
        this.Textbaozha.textColor = 0x000000;
        this.Textbaozha.size = 30;
        this.Textbaozha.x = this.baozha.x - 7;
        this.Textbaozha.y = this.baozha.y - 14;
        this.baozha.touchEnabled = true;
        this.baozha.addEventListener(egret.TouchEvent.TOUCH_TAP, this.BaozhaClick, this);
        this.falsekou = new MImage("ball_png");
        this.addChild(this.falsekou);
        this.falsekou.anchorOffsetX = this.falsekou.width >> 1;
        this.falsekou.anchorOffsetY = this.falsekou.height >> 1;
        this.falsekou.x = 400;//400
        this.falsekou.y = 1000;//1050
        this.falsekou.scaleX = 0.5;
        this.falsekou.scaleY = 0.5;
        this.shangdan1();
        var world: P2World = new P2World(0, 200);
        var walls: any[] = world.createWall(new egret.Rectangle(0, 0, GameData.stageWidth, GameData.stageHeight));
        this.addChild(world);
        this.world = world;
        world.loopBackFun = this.loopP2World.bind(this); 0
        this.material = new p2.Material();
        //创建炮
        var gun: Gun = new Gun;
        gun.addEvent(EVENT_FIRE, this.onFire, this)
        this.addChild(gun);
        this.gun = gun;
        gun.x = this.getCenterX(1);
        gun.y = GameData.stageHeight - 180;
        //创建上方炮
        var guntop: GunTop = new GunTop;
        guntop.addEvent(EVENT_FIRE, this.onFire, this)
        this.addChild(guntop);
        this.guntop = guntop;
        guntop.x = this.getCenterX(1);
        guntop.y = 130;

        //创建分享按钮 在舞台显示出来
        var xx: shareButton = new shareButton;
        this.addChild(xx);
        this.Share = xx;
        this.Share.x = 60;
        this.Share.y = 1050;
        GameControl.GameControlSole = this;
        this.Share.touchEnabled = true;
        // var pos11;
        // // pos11.x=319;
        // // pos11.y=541;
        // //  this.startBackFun(pos11);
        /**线 */

        // this.shape1.graphics.lineStyle(3, 0xf8f8ff);
        // this.shape1
        // this.shape1.graphics.moveTo(this.gun.x, this.gun.y);
        // this.shape1.graphics.lineTo(this.gun.x, -100);
        // this.shape1.graphics.endFill();
        // this.gun.line.scaleX = this.gun.x;
        // this.gun.line.scaleY = this.gun.y;

        // this.addChild(this.shape1);
        //  this.setChildIndex(this.shape1, 1);
        //this.shape1.visible = false;

        // this.addChild(this.shape1);



        //创建子弹  
       /* this.MagnifyBullet = new py2Obj.magnifyBullet(this.world, this, this.removeSkins);
        this.MagnifyBullet.init();
        this.MagnifyBullet.setPostion(-300, -300);
        this.boomBullet = new py2Obj.BoomBullet(this.world, this, this.removeSkins);
        this.boomBullet.init();
        this.boomBullet.setPostion(-200, -200);
        // console.log(this.boomBullet.m_body);*/
        /**普通子弹 */
        this.fakeBullet = new py2Obj.fakeBullet(this.world, this, this.removeSkins);
        //  this.fakeBullet = new py2Obj.BoomBullet(this.world, this, this.removeSkins);
        this.fakeBullet.init();
        this.fakeBullet.setPostion(-100, -100);
        /**不可停下子弹 */
        this.Bulebullet=new py2Obj.BlueBullet(this.world,this,this.removeSkins);
        this.Bulebullet.init();
        this.Bulebullet.setPostion(-700,-700);
       /* this.gravityBullet = new py2Obj.gravityBullet(this.world, this, this.removeSkins);
        this.gravityBullet.init();
        this.gravityBullet.setPostion(-400, -400);

        this.strikeBullet = new py2Obj.strikeBullet(this.world, this, this.removeSkins);
        this.strikeBullet.init();
        this.strikeBullet.setPostion(-500, -500);*/

        this.NowBullet = this.fakeBullet;
        //创建碰撞显示
        var ce: collideTime = new collideTime;
        this.addChild(ce);
        ce.x = -100; ce.y = -100;
        // this.NowBullet.addChild(ce);
        this.Collidetime = ce;

        //创建108固定显示
        var ww: strikeTime = new strikeTime;
        ww.x = -150; ww.y = -150;
        this.addChild(ww);
        this.Striketime = ww;

        //左上角分数的图片
        var img: egret.Bitmap = new egret.Bitmap();
        img.texture = RES.getRes("zuoshangjiaofenshu_png");
        this.addChild(img);
        //this.addChildAt(img,410);
        this.setChildIndex(img, 30)
        this.doMaterial(this.fakeBullet.getBody());
        /**砖块 */
        this.zhuan=new py2Obj.zhuanWall(this.world,this,this.removeSkins);
        this.zhuan.init();
        this.zhuan.setPostion(this.getCenterX(0),230);

        this.zhuanTop=new py2Obj.zhuanWall(this.world,this,this.removeSkins);
        this.zhuanTop.init();
        this.zhuanTop.setPostion(this.getCenterX(0),850);
        this.zhuanTXT=new TextField();
        this.zhuanTopTXT=new TextField();
        this.zhuanTXT.text=this.zhuan.m_num.toString();
        this.zhuanTXT.x=this.getCenterX(0);
        this.zhuanTXT.y=850;
        this.zhuanTopTXT.x=this.getCenterX(0);
        this.zhuanTopTXT.y=230;
        this.zhuanTopTXT.text=this.zhuanTop.m_num.toString();
        this.addChild(this.zhuanTXT);
        this.addChild(this.zhuanTopTXT);
        //两个玩家
        this.playOne=new py2Obj.qiu(this.world,this,this.removeSkins);
        this.playOne.init();
        this.playOne.setPostion(this.getCenterX(0),950);

        this.playOneHpTXT=new TextField();
        this.playOneHpTXT.x=50;
        this.playOneHpTXT.y=1080;
        this.playOneHpTXT.textColor=0x00c4a851;
        this.playOneHpTXT.text="剩余HP:"+this.playOneHp;
        this.addChild(this.playOneHpTXT);

        this.playTwoHpTXT=new TextField();
        this.playTwoHpTXT.x=50;
        this.playTwoHpTXT.y=20;
        this.playTwoHpTXT.textColor=0x00c4a851;
        this.playTwoHpTXT.text="剩余HP:"+this.playTwoHp;
        this.addChild(this.playTwoHpTXT);

        this.playTwo=new py2Obj.qiu(this.world,this,this.removeSkins);
        this.playTwo.init();
        this.playTwo.setPostion(this.getCenterX(0),130);
        /**墙 */
        var TopWall = new py2Obj.bottomWall(this.world, this, this.removeSkins);
        TopWall.init();
        var DiWall = new py2Obj.bottomWall(this.world, this, this.removeSkins);
        DiWall.init();
        var liftWall = new py2Obj.basicWall(this.world, this, this.removeSkins);
        liftWall.init();
        var rightWall = new py2Obj.basicWall(this.world, this, this.removeSkins);
        rightWall.init();
        var pipeHight: number = liftWall.getBody().userData.skin.height / 2;
        var pipeY: number = this.setBottom(pipeHight, 100);
        liftWall.setPostion(-25, pipeY);
        rightWall.setPostion(this.getRight(-25), pipeY);
        TopWall.setPostion(this.getCenterX(0), -65);
        DiWall.setPostion(this.getCenterX(0), GameData.stageHeight + 65);

        //生成道具
        this.m_PropManager = new py2Obj.PropManager(this.world, this, this.removeSkins);
        // this.m_PropManager.createProp();//原来的
        this.m_PropManager.createPropXinShou();//新手引导

        // this.m_PropManager.createProp(2);
        this.m_PropManager.m_props[0];
        this.m_PropManager.m_props1[0].setPostion(-1000,-100);
        

        //  this.createBottom();
        this.container = new Sprite;
        this.addChild(this.container);
        var conMask: Sprite = moon.MoonUI.getRect(GameData.stageWidth, GameData.stageHeight - 200, 0, 0, 160);
        this.container.mask = conMask;

        var controlGun: control.ControlBasic = new control.ControlBasic(this.stage);
        //controlGun.open();
        //this.Share.addEventListener(egret.TouchEvent.TOUCH_TAP,this.shareEvent,this);
        //  controlGun.clickShare = this.shareEvent.bind(this);//点击分享按钮（触发的事件）
        controlGun.startBackFun = this.startBackFun.bind(this);//摁下
        controlGun.moveBackFun = this.controlMove.bind(this);//移动
        controlGun.endBackFun = this.endBackFun.bind(this);//离开
        //controlGun.endBackFun = this.startBackFun.bind(this);//离开
        this.fashe.touchEnabled = true;//图片获取监听事件权限
        this.fashe.addEventListener(egret.TouchEvent.TOUCH_END, this.endBackFun1, this);//创建按钮监听事件bool
        this.fashe.addEventListener(egret.TouchEvent.TOUCH_END, this.endBackFun, this);
        this.Share.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.shareEvent, this);
        this.adjustment.addEventListener(egret.TouchEvent.TOUCH_TAP, this.qie, this);
        this.controlGun = controlGun;

        world.p2World.on("beginContact", this.onHitBegin.bind(this));
        world.p2World.defaultContactMaterial.restitution = 1;//反弹力
        //  world.p2World.on("impact",this.onHitImpact.bind(this));
        // world.p2World.on("postStep",this.onHitImpact.bind(this));
        this.txtScore = this.createText(50, 50);

        //this.txtScore.textColor=0;
        this.txtLevel = this.createText(200, -200);
        //this.initGame();
        //this.play();
        // this.updateNumBody();
        //this.testZero()
        this.bei = new MImage("bg_jpg");
        this.addChild(this.bei);
        this.addEventListener(egret.Event.ENTER_FRAME, this.huihe, this)
        this.addEventListener(egret.Event.ENTER_FRAME, this.timerFunc, this);//每帧执行方法
        this.addEventListener(egret.Event.ENTER_FRAME,this.bulletimg,this)
        this.addEventListener(egret.Event.ENTER_FRAME,this.updateHPTXT,this);
        //关闭不需要的组件
        this.chufa.visible=false;
        this.fangda.visible=false;
        this.baozha.visible=false;
        this.zhongli.visible=false;
        this.Textbaozha.visible=false;
        this.Textchufa.visible=false;
        this.Textfangda.visible=false;
        this.Textzhongli.visible=false;
        this.falsekou.visible=false;
        this.faan.visible=false;
        this.Share.visible=false;
        img.visible=false;

       
    }
    public updateHPTXT()
    {
        this.playOneHpTXT.text="剩余HP:"+this.playOneHp;
        this.playTwoHpTXT.text="剩余HP:"+this.playTwoHp;
        this.zhuanTXT.text=this.zhuan.m_num.toString();
        this.zhuanTopTXT.text=this.zhuanTop.m_num.toString();
        if(this.playOneHp==0||this.playTwoHp==0)
        {
          this.over();
        }
        if(!this.qiehuan)
        {
            this.Collidetime.txtNum1.visible=true;

        }
        else 
        {
             this.Collidetime.txtNum1.visible=false;

        }
    }
    public shengyin() {
        SoundControl.getIns().play(MUSIC_BG, 0, 9999);
    }
    public ChufaClick() {
        if (this.ChufaCount > 0) {

            this.ChufaCount -= 1;
            this.Textchufa.text = this.ChufaCount.toString();
            var pos1 = new egret.Point(this.my_chuchun[0].tu.x, this.my_chuchun[0].tu.y);
            this.changeColor2(0, pos1, 2)
            this.my_chuchun[0].objkind = 2//触发子弹

        }
    }
    public BaozhaClick() {
        if (this.BaozhaCount > 0) {
            var pos1 = new egret.Point(this.my_chuchun[0].tu.x, this.my_chuchun[0].tu.y);
            this.BaozhaCount -= 1;
            this.Textbaozha.text = this.BaozhaCount.toString();
            this.changeColor2(0, pos1, 5)
            this.my_chuchun[0].objkind = 5//爆炸子弹

        }
    }
    public FangdaClick() {
        if (this.FangdaCount > 0) {
            var pos1 = new egret.Point(this.my_chuchun[0].tu.x, this.my_chuchun[0].tu.y);
            this.FangdaCount -= 1;
            this.Textfangda.text = this.FangdaCount.toString();
            this.changeColor2(0, pos1, 3)
            this.my_chuchun[0].objkind = 3//放大子弹

        }
    }
    public ZhongliClick() {
        if (this.ZhongliCount > 0) {
            var pos1 = new egret.Point(this.my_chuchun[0].tu.x, this.my_chuchun[0].tu.y);
            this.ZhongliCount -= 1;
            this.Textzhongli.text = this.ZhongliCount.toString();
            this.changeColor2(0, pos1, 4)
            this.my_chuchun[0].objkind = 4//重力子弹

        }
    }
    /**分享事件 */
    public shareEvent() {
        if (this.fenxiang) {

            this.shareNum += 1;
            if (this.shareNum == 1) {
                var timer: egret.Timer = new egret.Timer(500, 5);
                timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.timerComFunc1, this);
                timer.start();
            }
            platform.activeShare();
            platform.findShareQuery(this.shengyin);

        }
    }
    private timerComFunc1() {
        this.gun.bullet += 1;
        this.gun.updateNum(this.gun.bullet);
    }
    /*public qie() {

        if (this.qiehuan) {
            this.faan.visible = true;
            this.addEvent(egret.Event.ADDED_TO_STAGE, this.controlMove, this);
            this.qiehuan = false;
            this.Weitiaojuli = 150;
            //新手指导 
            this.Newarrow.visible = true;
            this.Newarrow1.visible = false;
            egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁    
            // this.adjustment.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            // this.bj.visible=false;
            // this.removeChild(this.bj);
            //this.upgradeNumber2 = 5;//新手引导
            //this.jixucishu+=1;

            //this.removeChild(this.btn);
        }
        else if (!this.qiehuan) {
            this.removeEventListener(egret.Event.ADDED, this.controlMove, this);
            this.faan.visible = false;
            this.qiehuan = true;
            this.Weitiaojuli = 0;
            this.Newarrow.visible = false;
            this.Newarrow1.visible = true;
            egret.Tween.get(this.Newarrow1, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁   
            // this.addChild(this.bj);
            // this.bj.visible=true;
            // this.removeChild(this.bj);
            // // this.removeChild(this.btn);
            // if (this.upgradeNumber3 != 0) {
            //     this.upgradeNumber3 = 0;
            //     //this.upgradeNumber2=0;
            // }

        }

    }*/
    public huihe()
    {
      if(this.istop)
      {
        this.guntop.showLine();
        this.gun.hideLine();
        this.xiaoluntop.visible=true;
        this.xiaofaan.visible=false;
        this.playTwo.m_body.collisionResponse=false;
        this.playOne.m_body.collisionResponse=true;
        this.playTwo.objkind=10000;
        this.playOne.objkind=500;
        this.zhuanTop.setPostion(-600,-600);
        if(this.zhuan.m_num>0)
        { 
        this.zhuanTXT.visible=true;
        this.zhuan.setPostion(this.getCenterX(0),850);
       }
       else
       {
          this.zhuanTXT.visible=false;
       }
        this.zhuanTopTXT.visible=false;
    
        this.zhuanTop.objkind=10000;
        this.zhuan.objkind=600;
      }
    else if(!this.istop)
      {

       this.gun.showLine();
       this.guntop.hideLine();
       this.xiaoluntop.visible=false;
       this.xiaofaan.visible=true;
       this.playOne.m_body.collisionResponse=false;
       this.playTwo.m_body.collisionResponse=true;
       this.playOne.objkind=10000;
       this.playTwo.objkind=500;
       this.zhuan.setPostion(-600,-600);
       if(this.zhuanTop.m_num>0)
       {
         this.zhuanTop.setPostion(this.getCenterX(0),230);
          this.zhuanTopTXT.visible=true;
       }
       else
       {
         this.zhuanTopTXT.visible=false;
       }
      
      
       this.zhuanTXT.visible=false;
       this.zhuan.objkind=10000;
       this.zhuanTop.objkind=600;
      }
    }
    public qie()
    {
        if(!this.qiehuan)
        {
            this.qiehuan=true;
            this.Collidetime.txtNum1.visible=false;

        }
        else 
        {
            this.qiehuan=false
             this.Collidetime.txtNum1.visible=true;

        }
    }
    public bulletimg()
    {
        if(this.qiehuan)
        {
            this.nowBulletImgBule.visible=true;
            this.nowBulletImg.visible=false;
        }
        else
        {
            this.nowBulletImgBule.visible=false;
            this.nowBulletImg.visible=true;
        }
    }
    //碰撞次数显示位置
    public timerFunc() {

        // if (!this.yinxiaoBool) {
        //     SoundControl.getIns().play(MUSIC_BG, 0, 9999);
        //     this.yinxiaoBool = true;
        // }
        if (this.faguang) {
            var color: number = 0x33CCFF;        /// 光晕的颜色，十六进制，不包含透明度
            var alpha: number = 0.8;             /// 光晕的颜色透明度，是对 color 参数的透明度设定。有效值为 0.0 到 1.0。例如，0.8 设置透明度值为 80%。
            var blurX: number = 0;              /// 水平模糊量。有效值为 0 到 255.0（浮点）
            var blurY: number = 0;              /// 垂直模糊量。有效值为 0 到 255.0（浮点）
            var strength: number = 5;            /// 压印的强度，值越大，压印的颜色越深，而且发光与背景之间的对比度也越强。有效值为 0 到 255。暂未实现
            var quality: number = egret.BitmapFilterQuality.HIGH;        /// 应用滤镜的次数，建议用 BitmapFilterQuality 类的常量来体现
            var inner: boolean = false;            /// 指定发光是否为内侧发光，暂未实现
            var knockout: boolean = false;            /// 指定对象是否具有挖空效果，暂未实现
            var glowFilter: egret.GlowFilter = new egret.GlowFilter(color, alpha, blurX, blurY, strength, quality, inner, knockout);
            this.glowFilter = glowFilter;
            this.gun.line.filters = [this.glowFilter];
        }
        else {
            this.gun.line.filters = [];
        }
        // if (this.my_chuchun.length > 0) {
        //     if (this.NowBullet.isRun == false && this.boomNum >= 4 && this.my_chuchun[0].objkind == 1)//判断第五发是爆炸球
        //     {
        //         this.sffaqiu = true;
        //         this.removeChild(this.my_chuchun[0].tu)
        //         var tu = new MImage(lizitexiao[5]);
        //         this.addChild(tu);
        //         tu.anchorOffsetX = tu.height >> 1;
        //         tu.anchorOffsetY = tu.width >> 1;
        //         tu.x = 319;
        //         tu.y = 887;
        //         egret.Tween.get(tu).to({ scaleX: 2, scaleY: 2 }, 500).call(() => {
        //             this.removeChild(tu)
        //             this.my_chuchun[0].objkind = 5;
        //             var pos2 = new egret.Point(319, 887)
        //             this.changeColor2(0, pos2, 5)
        //             this.sffaqiu = false;
        //         })
        //         egret.Tween.get(tu).to({ alpha: 0 }, 500)

        //         this.boomNum = 0;
        //     }
        // }
        //判断发射球的半径
        if (this.NowBullet.isRun == false && this.shu11 == 0) {
            if (this.my_chuchun.length != 0) {
                if (this.my_chuchun[0].objkind == 3) {
                    this.e = 45;
                }
                else {
                    this.e = 13;
                }
            } else {
                this.e = 13;
            }
            this.shu11 = 1;
            if (this.fashezhuo == null) {
                var pos;
                pos = { x: this.gun.x, y: this.gun.y - 100 }
                this.fashezhuo = pos;
                this.startBackFun(pos);
            }
            else {
                this.startBackFun(this.fashezhuo);
            }
            Tween.get(this.faan).to({ alpha: 1 }, 200);
        }
        if (this.NowBullet.isRun == true) {
            this.Collidetime.x = this.NowBullet.m_body.position[0] - 5;
            this.Collidetime.y = this.NowBullet.m_body.position[1] - 5;
        }

        if (this.NowBullet.m_body.position[0] < 0 || this.NowBullet.m_body.position[0] > 634 || this.NowBullet.m_body.position[1] < 0 || this.NowBullet.m_body.position[1] > 1691) {
            this.NowBullet.isRun = false;
        }
        // if (this.gun.bullet <= 0 && this.NowBullet.isRun == false) {
        //     this.isOver = 1;
        //     this.over();
        //     //this.NowBullet.isRun=true;

        // }
        if (this.overValue == 0) {
            for (var i = 0; i < this.my_strikeBall.length; i++) {
                if (this.my_strikeBall[i].objkind == 108) {
                    this.Striketime.x = this.my_strikeBall[i].m_body.position[0] - 5;
                    this.Striketime.y = this.my_strikeBall[i].m_body.position[1] - 5;
                    this.Striketime.updateNum(this.Striketime.chufashuzi);
                    this.addChild(this.Striketime);


                }
            }
        }
    }
    public timerComFunc() {

    }

    protected initView(): void {
        //需要复写
    }
    public initGame(): void {
        this.score = 0;
        //  this.level = 0;
        this.ballNum = 0;
        this.moveNum = 0;
        this.gun.restart();
        this.guntop.restart();
        //this.updateScore();
        this.controlGun.open();
        this.playOneHp=5;
        this.playTwoHp=5;
        this.chushihua();
    }
    public chushihua()
    {
        this.zhuan.setPostion(this.getCenterX(0),230);
        this.zhuan.m_num=5;
        this.zhuanTop.m_num=5;
        this.zhuanTop.setPostion(this.getCenterX(0),850);
        this.huiheNum=0;
    }
    /**复活 */
    public revive(): void {
        this.moveNum = 0;
        this.ballNum = 0;
        this.play();
        this.controlGun.open();
    }
    protected setBottom(height: number, distance: number): number {
        return GameData.stageHeight - height - distance;
    }
    protected moveNumBody(): void {
        var bodys = this.world.p2World.bodies;
        var l: number = bodys.length;
        for (var i: number = 0; i < l; i++) {
            var body: p2.Body = bodys[i];
            if (body.userData && body.userData.skin) {
                if (body.userData["num"]) {
                    body.position[1] -= 10;
                    if (body.position[1] <= OVER_DIS) {
                        if (body.userData.skin.imageName != ICON_ADD) {
                            this.over();
                            return;
                        }
                    }
                }
            }
        }
        if (this.moveNum < 7) {
            this.moveNum++
            setTimeout(this.moveNumBody.bind(this), 50);
        } else {
            this.moveNum = 0;
            this.controlGun.open();
        }
    }
    /**结束 */
    public over(): void {
        super.over();
        this.controlGun.close();
        var bodys = this.world.p2World.bodies;
        this.empty();
        /**新手指导 */
        this.empty1();//如果场景里存在金币，清除金币
        this.count = 0;
        this.upgradeNumber = 1;
        this.shareNum = 0;
        this.gun.gun.rotation = 180;
        this.gun.ball.rotation = 180;
        this.BaozhaCount = 0;
        this.ChufaCount = 0;
        this.ZhongliCount = 0;
        this.FangdaCount = 0;
        this.Textchufa.text = this.ChufaCount.toString();
        this.Textbaozha.text = this.BaozhaCount.toString();
        this.Textzhongli.text = this.ZhongliCount.toString();
        this.Textfangda.text = this.FangdaCount.toString();
        // this.NowBullet1 = this.fakeBullet;
        // this.changeColor1();
        this.sffaqiu = false;
        this.shangdan1();
        this.my_ball = [];
        this.boomNum = 0;
        this.m_PropManager.allProps = [];
        this.isOver = 0;
        this.upgradeNumber = 1;
        if (this.m_PropManager.m_props1.length == 0) {
            //  this.m_PropManager.createProp();//原来的
            this.m_PropManager.createPropXinShou();//新手引导
        }
        // this.removeFromParent(this.Striketime);
        // if (this.Striketime != null) {
        this.my_strikeBall = [];
        this.Striketime.chufashuzi = 3;
        this.Striketime.x = -100;
        this.Striketime.y = -100;
        this.Collidetime.x = -150;
        this.Collidetime.y = -150;
        this.overValue = 1;

        // this.addChild(this.Striketime);
        //this.removeChild(this.Striketime);
        //  }

        this.sendMsg(GameData.score);

        // console.log(GameData.score);

        // this.my_ball.push(this.m_PropManager.m_props[0]);
        // this.m_PropManager=null;
        // this.m_PropManager = new py2Obj.PropManager(this.world, this, this.removeSkins);
        // this.m_PropManager.createProp(1);
        // this.m_PropManager.m_prop/**/s[0];
    }
    /*调取开放域*/
    private sendMsg(n) {
        // let platform: any = window.platform;
        // platform.openDataContext.postMessage({
        //     score: n.toString()
        // });
    }
    public empty(): void {
        var bodys = this.world.p2World.bodies;
        for (var i: number = 0; i < bodys.length; i++) {
            var body: p2.Body = bodys[i];
            if (body.userData && body.userData.skin) {
                if (body.userData.data.objkind == 100 || body.userData.data.objkind == 108/*||body.userData.data.objkind == 400||body.userData.data.objkind == 401*/) {
                    var skin: MImage = body.userData.skin;
                    this.world.removeBodys.push(body);
                    skin.removeFromParent(true);
                }

            }
        }
    }
    /** */
    public empty1(): void {
        var bodys = this.world.p2World.bodies;
        for (var i: number = 0; i < bodys.length; i++) {
            var body: p2.Body = bodys[i];
            if (body.userData && body.userData.skin) {
                if (body.userData.data.objkind == 400) {
                    var skin: MImage = body.userData.skin;
                    this.world.removeBodys.push(body);
                    skin.removeFromParent(true);
                }

            }
        }
    }
    protected updateNumBody(): void {
        return;
    }

    /**帧动画 */
    private frameAnimation(X: number, y: number) {
        var texture2mc = RES.getRes("Boom_png");
        var data2mc = RES.getRes("Boom_json");
        let mcFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data2mc, texture2mc);
        let mc: egret.MovieClip = new egret.MovieClip(mcFactory.generateMovieClipData("Boom"));
        this.addChild(mc);
        mc.gotoAndPlay("Boom", 1);//"A" : Boom -1 ： 循环播放				
        mc.x = X - 60;
        mc.y = y - 60;
        mc.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
            this.removeChild(mc);
        }, this);
        this.Collidetime.x = -55;
        this.Collidetime.y = -55;
    }
    private shangdan1() {
        if (this.my_chuchun.length < 1) {
            var a = new chun;
            a.tu = new MImage("ball_png")
            a.objkind = 1;
            a.tu.anchorOffsetX = a.tu.width / 2;
            a.tu.anchorOffsetY = a.tu.height / 2;
            a.tu.x = 319;//264
            a.tu.y = 10000;//922
            this.addChild(a.tu);
            this.my_chuchun.push(a);


            // this.shangdan();
        }
    }
    /**确定 */
    private que(a: number, b: number): number {
        var c = 3;
        if (a == 887) {
            c = 0
        } if (a == 1000) {
            c = 1
        } if (a == 1000 && b == 320) {
            c = 2
        }
        return c;
    }
    /**上子弹 */
    // private shangdan() {
    //     //改变子弹运行轨迹
    //     if (this.my_chuchun.length > 0) {
    //         if (this.my_chuchun[0].tu.x == 320) {
    //             egret.Tween.get(this.my_chuchun[0].tu).to({ x: 240, y: 1000 }, 200).to({ x: 319, y: 887 }, 200)
    //         }
    //         else if (this.my_chuchun[0].tu.x == 240 || this.my_chuchun[0].tu.x == 319) {
    //             egret.Tween.get(this.my_chuchun[0].tu).to({ x: 319, y: 887 }, 200)
    //         }
    //         else {
    //             egret.Tween.get(this.my_chuchun[0].tu).to({ x: 320, y: 1000 }, 200).to({ x: 240, y: 1000 }, 200).to({ x: 319, y: 887 }, 200)
    //         }
    //         if (this.my_chuchun.length >= 2) {
    //             if (this.my_chuchun[1].tu.x == 320 || this.my_chuchun[1].tu.x == 240) {
    //                 egret.Tween.get(this.my_chuchun[1].tu).to({ x: 240, y: 1000 }, 200)
    //             }

    //             else {
    //                 egret.Tween.get(this.my_chuchun[1].tu).to({ x: 320, y: 1000 }, 200).to({ x: 240, y: 1000 }, 200)
    //             }
    //         } if (this.my_chuchun.length >= 3) {
    //             egret.Tween.get(this.my_chuchun[2].tu).to({ x: 320, y: 1000 }, 200)
    //         }
    //     }

    // }
    /**其他吃到道具金币粒子特效 */
    private liziy(zhu: egret.Point, shu: number, shu2: number) {
        this.sffaqiu = true;
        if (zhu.x > 0 && this.gun.bullet > 0 || zhu.x > 0 && this.gun.bullet <= 0 && shu == 1) {
            var pos = new egret.Point(0, 0);
            var shudu = 0;
            if (shu == 0)//确定粒子运动的位置
            {
                SoundControl.getIns().addItem(MUSIC_Jinbi);
                SoundControl.getIns().play(MUSIC_Jinbi);
                pos = new egret.Point(45, 33)
                // shudu = Math.sqrt(Math.pow(zhu.x - 45, 2) + Math.pow(zhu.y - 40, 2))
            }
            else if (shu == 1) {
                console.log(this.jiaQiuCount);

                SoundControl.getIns().addItem(MUSIC_Eatdaoju);
                SoundControl.getIns().play(MUSIC_Eatdaoju);
                if (this.upgradeNumber == 1) {
                    shudu = Math.sqrt(Math.pow(zhu.x - 274, 2) + Math.pow(zhu.y - 1094, 2))
                    pos = new egret.Point(274, 1094)
                }
                else {
                    if (this.jiaQiuCount > 0) {
                        shudu = Math.sqrt(Math.pow(zhu.x - 274, 2) + Math.pow(zhu.y - 1094, 2))
                        pos = new egret.Point(274, 1094)
                    }
                }

            }
            else if (shu == 2) {
                SoundControl.getIns().addItem(MUSIC_Eatdaoju);
                SoundControl.getIns().play(MUSIC_Eatdaoju);
                shudu = Math.sqrt(Math.pow(zhu.x - 210, 2) + Math.pow(zhu.y - 1010, 2))
                pos = new egret.Point(210, 1010)
                // for (let i = 0; i < this.my_chuchun.length; ++i) {
                //     if (this.my_chuchun[i].objkind == 1) {
                //         pos = new egret.Point(this.my_chuchun[i].tu.x, this.my_chuchun[i].tu.y);
                //         this.my_chuchun[i].objkind = shu;

                //         break;
                //     }
                // }

                /** 箭头指示*/
                this.Newjiantou.visible = false;
            }
            else if (shu == 3) {
                SoundControl.getIns().addItem(MUSIC_Eatdaoju);
                SoundControl.getIns().play(MUSIC_Eatdaoju);
                shudu = Math.sqrt(Math.pow(zhu.x - 280, 2) + Math.pow(zhu.y - 1010, 2))
                pos = new egret.Point(280, 1010)

                /** 新手指导箭头指示*/
                this.Newjiantou.visible = false;

            }
            else if (shu == 4) {

                SoundControl.getIns().addItem(MUSIC_Eatdaoju);
                SoundControl.getIns().play(MUSIC_Eatdaoju);
                shudu = Math.sqrt(Math.pow(zhu.x - 350, 2) + Math.pow(zhu.y - 1010, 2))
                pos = new egret.Point(350, 1010)

                /** 新手指导箭头指示*/
                this.Newjiantou.visible = false;


            }
            else if (shu == 5) {
                SoundControl.getIns().addItem(MUSIC_Eatdaoju);
                SoundControl.getIns().play(MUSIC_Eatdaoju);
                shudu = Math.sqrt(Math.pow(zhu.x - 420, 2) + Math.pow(zhu.y - 1010, 2))
                pos = new egret.Point(420, 1010)

                /** 箭头指示*/
                this.Newjiantou.visible = false;


            }
            var texture = RES.getRes(lizitexiao[shu]);//粒子特效
            var config = RES.getRes("FangdaQiu_json");
            var particleSys = new particle.GravityParticleSystem(texture, config);
            particleSys.emitterX = zhu.x;
            particleSys.emitterY = zhu.y;
            this.addChild(particleSys);
            particleSys.start(shudu / 0.7);
            egret.Tween.get(particleSys).to({ emitterX: pos.x, emitterY: pos.y }, shudu / 0.7).call(() => {//粒子tween动画，储存子弹类型，改变颜色
                if (particleSys.emitterX == 210 && particleSys.emitterY == 1010)//储存触发子弹
                {
                    // this.my_chuchun2.push(shu);
                    this.ChufaCount++;
                    this.Textchufa.text = this.ChufaCount.toString();
                    this.upgradeNumber2 = 53;//新手引导
                    this.UpgradeTishi();
                }
                if (particleSys.emitterX == 280 && particleSys.emitterY == 1010)//储存放大子弹种类
                {
                    this.FangdaCount++;
                    this.Textfangda.text = this.FangdaCount.toString();
                    this.upgradeNumber2 = 52;//
                    this.UpgradeTishi();

                }
                if (particleSys.emitterX == 350 && particleSys.emitterY == 1010)//储存重力子弹种类
                {
                    this.ZhongliCount++;
                    this.Textzhongli.text = this.ZhongliCount.toString();
                    this.upgradeNumber2 = 54;//新手引导
                    this.UpgradeTishi();
                }
                if (particleSys.emitterX == 420 && particleSys.emitterY == 1010)//储存爆炸子弹种类
                {
                    this.BaozhaCount++;
                    this.Textbaozha.text = this.BaozhaCount.toString();
                    this.upgradeNumber2 = 51;//新手引导
                    this.UpgradeTishi();
                }

                var tu = new MImage(lizitexiao[shu]);
                this.addChild(tu);
                tu.anchorOffsetX = tu.height >> 1;
                tu.anchorOffsetY = tu.width >> 1;
                tu.x = particleSys.emitterX;
                tu.y = particleSys.emitterY;
                egret.Tween.get(tu).to({ scaleX: 2, scaleY: 2 }, 500).call(() => { this.removeChild(tu) })
                egret.Tween.get(tu).to({ alpha: 0 }, 500)
                var time1 = new egret.Timer(150, 1)
                time1.start()
                time1.addEventListener(egret.TimerEvent.TIMER, (eve: egret.Event) => {
                    this.sffaqiu = false;

                    var que = this.que(tu.y, tu.x);
                    if (shu != 0 && shu != 1 && que != 3) {
                        var pos1 = new egret.Point(this.my_chuchun[que].tu.x, this.my_chuchun[que].tu.y);
                        this.removeChild(this.my_chuchun[que].tu)
                        this.changeColor2(que, pos1, shu)

                    }
                    if (shu == 0)//判断加分数或子弹
                    {
                        this.count += 1;
                        this.upgradeNumber2 = 3;//新手引导
                        this.UpgradeTishi();
                        this.score = this.count;
                        this.updateScore();
                        if (this.count >= 20 && this.upgradeNumber == 1) {
                            this.Upgrade();
                            this.upgradeNumber += 1;
                        }
                        else if (this.count >= 50 && this.upgradeNumber == 2) {
                            this.Upgrade();
                            this.upgradeNumber += 1;
                        }
                        else if (this.count >= 80 && this.upgradeNumber == 3) {
                            this.Upgrade();
                            this.upgradeNumber += 1;
                        }


                    } else if (shu == 1) {
                        if (this.upgradeNumber == 1) {
                            this.gun.updateNum(++(this.gun.bullet));
                        }
                        else {
                            if (this.jiaQiuCount > 0) {
                                this.gun.updateNum(++(this.gun.bullet));
                            }
                        }

                    }
                }, this)
            })
            if (shu2 != 0) {

                var time = new egret.Timer(400, shu2)
                time.start()
                time.addEventListener(egret.TimerEvent.TIMER, (eve: egret.Event) => {
                    var texture = RES.getRes(lizitexiao[shu]);//粒子特效
                    var config = RES.getRes("FangdaQiu_json");
                    var particleSys = new particle.GravityParticleSystem(texture, config);
                    particleSys.emitterX = zhu.x;
                    particleSys.emitterY = zhu.y;
                    this.addChild(particleSys);
                    particleSys.start(shudu / 0.7);
                    egret.Tween.get(particleSys).to({ emitterX: pos.x, emitterY: pos.y }, shudu / 0.7).call(() => {//粒子tween动画，储存子弹类型，改变颜色
                        if (pos.x == 210 && pos.y == 1010)//储存子弹种类
                        {
                            this.ChufaCount++;
                            this.Textchufa.text = this.ChufaCount.toString();
                            //  this.my_chuchun2.push(shu);
                        }
                        if (pos.x == 280 && pos.y == 1010)//储存放大子弹种类
                        {
                            this.FangdaCount++;
                            this.Textfangda.text = this.FangdaCount.toString();
                        }
                        if (pos.x == 350 && pos.y == 1010)//储存重力子弹种类
                        {
                            this.ZhongliCount++;
                            this.Textzhongli.text = this.ZhongliCount.toString();
                        }
                        if (pos.x == 420 && pos.y == 1010)//储存爆炸子弹种类
                        {
                            this.BaozhaCount++;
                            this.Textbaozha.text = this.BaozhaCount.toString();
                        }
                        var tu = new MImage(lizitexiao[shu]);
                        this.addChild(tu);
                        tu.anchorOffsetX = tu.height >> 1;
                        tu.anchorOffsetY = tu.width >> 1;
                        tu.x = particleSys.emitterX;
                        tu.y = particleSys.emitterY;

                        egret.Tween.get(tu).to({ scaleX: 2, scaleY: 2 }, 500).call(() => { this.removeChild(tu) })
                        egret.Tween.get(tu).to({ alpha: 0 }, 500)
                        var time2 = new egret.Timer(150, 1)
                        time2.start()
                        time2.addEventListener(egret.TimerEvent.TIMER, (eve: egret.Event) => {

                            this.sffaqiu = false;
                            var que = this.que(tu.y, tu.x);
                            if (shu != 0 && shu != 1 && que != 3) {
                                var pos1 = new egret.Point(this.my_chuchun[que].tu.x, this.my_chuchun[que].tu.y);
                                this.removeChild(this.my_chuchun[que].tu)
                                console.log("--------++++++++++--------------" + que)
                                this.changeColor2(que, pos1, shu)

                            }
                            if (shu == 0)//判断加分数或子弹
                            {
                                this.count += 1;
                                this.score = this.count;
                                this.updateScore();
                            } else if (shu == 1) {
                                if (this.upgradeNumber == 1) {
                                    this.gun.updateNum(++(this.gun.bullet));//4444444444
                                } else {
                                    if (this.jiaQiuCount > 0) {
                                        this.gun.updateNum(++(this.gun.bullet));//4444444444
                                    }
                                }
                            }
                        }, this)
                    })
                    //  egret.Tween.get(particleSys).to({x:320,y:880},2000)
                }, this);
            }
        }
    }
    /**改变子弹颜色 */
    private changeColor2(a: number, zhu: egret.Point, shu: number) {
        this.my_chuchun[a].tu = new MImage(lizitexiao[shu])
        this.addChild(this.my_chuchun[a].tu);
        this.my_chuchun[a].tu.anchorOffsetX = this.my_chuchun[a].tu.width / 2;
        this.my_chuchun[a].tu.anchorOffsetY = this.my_chuchun[a].tu.height / 2;
        this.my_chuchun[a].tu.x = zhu.x;
        this.my_chuchun[a].tu.y = zhu.y;
    }
    /**关卡界面*/
    private Upgrade() {
        /**新手指导 */
        // if (tishi != 5) {
        //     tishi += 1;
        //     this.upgradeNumber2 += 1;
        // }
        // else if (tishi == 5) {
        //     return;
        // }

        var bj = new MImage("startPanel1_png");
        this.bj = bj;
        var btn: MButton = new MButton(new MImage("btnStart_png"), new MImage("btnStart_png"));
        this.btn = btn;
        this.addChild(this.bj);
        this.addChild(this.btn);
        btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
        btn.x = (this.stageWidth - btn.width) >> 1;
        btn.y = 650;
        var upgradeText: egret.TextField = new egret.TextField();
        upgradeText.width = 400;
        upgradeText.height = 400;
        upgradeText.x = 140;
        upgradeText.y = 400;
        upgradeText.textColor = 0x00c4a851;
        upgradeText.size = 30;
        upgradeText.textAlign = egret.HorizontalAlign.CENTER;

        //  upgradeText.verticalAlign = egret.VerticalAlign.MIDDLE;
        if (this.upgradeNumber == 1) {
            upgradeText.text = "难度增加\n\n直接撞击金币不加子弹，经过反弹后打到金币才加子弹";
        }
        else if (this.upgradeNumber == 2) {
            upgradeText.text = "难度增加\n\n道具出现概率降低"
        }
        else if (this.upgradeNumber == 3) {
            upgradeText.text = "星空中随机出现金币数量增加"
        }
        else if (this.upgradeNumber == 4) {
            upgradeText.text = "难度增加\n\n星空中随机出现金币，打不到消失"
        }


        bj.addChild(upgradeText);
    }
    public UpgradeTishi() {
        // var xinbool=egret.localStorage.getItem("xinshouyindao");
        // if(xinbool=="false")   
        // console.log("啦啦啦啦啦啦" + egret.localStorage.getItem("xinshouyindao"));
        // if (egret.localStorage.getItem("xinshouyindao") == "false") {

        /**新手指导 */
        if (tishi != 9) {
            tishi += 1;
            // this.upgradeNumber2 += 1;//新手引导
        }
        else if (tishi == 9) {
            return;
        }

        var bj = new MImage("startPanel1_png");
        this.bj = bj;

        var btn: MButton = new MButton(new MImage("jixu_png"), new MImage("jixu_png"));
        this.btn = btn;

        btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
        btn.x = (this.stageWidth - btn.width) >> 1;
        btn.y = 650;
        var upgradeText: egret.TextField = new egret.TextField();
        upgradeText.width = 400;
        upgradeText.height = 400;
        upgradeText.x = 140;
        upgradeText.y = 400;
        upgradeText.textColor = 0x00c4a851;
        upgradeText.size = 32;
        upgradeText.textAlign = egret.HorizontalAlign.CENTER;
         var text3: egret.TextField = new egret.TextField();
            text3.text = "点击发射按钮或空白处继续";
            text3.textColor = 0x00c4a851;
            text3.size = 32;
            text3.width = 1000;
            text3.x = 140;
            text3.y = 700;
        if (this.upgradeNumber2 == 100 && this.upgradeNumber3 == 0) {
            var bj = new MImage("startPanel1_png");
            this.bj = bj;
            var btn: MButton = new MButton(new MImage("jixu_png"), new MImage("jixu_png"));
            this.btn = btn;
            btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            btn.x = (this.stageWidth - btn.width) >> 1;
            btn.y = 650;
            var upgradeText: egret.TextField = new egret.TextField();
            upgradeText.width = 400;
            upgradeText.height = 400;
            upgradeText.x = 140;
            upgradeText.y = 400;
            upgradeText.textColor = 0x00c4a851;
            upgradeText.size = 32;
            upgradeText.textAlign = egret.HorizontalAlign.CENTER;
            this.upgradeNumber3 = 1;//防止弹出界面同时出现
            tanChuang=1;
            upgradeText.text = "点击发射按钮"
            bj.addChild(upgradeText);
            this.addChild(this.bj);
            this.addChild(this.fashe);//新手引导
            this.Newarrow.visible = true;
            this.Newarrow1.visible = false;
           


            // egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
            // this.addChild(this.Newarrow);
            //egret.Tween.get(this.Newarrow,{loop:true}).to({ alpha: 0}, 200).to({ alpha: 1}, 200); //颜色闪烁    
            egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
        }
      else  if (this.upgradeNumber2 == 2 && this.upgradeNumber3 == 0) {
            this.upgradeNumber3 = 2;
            tanChuang=1;
            this.upgradeNumber4 = 2;
           // bj.addChild(text3)

            upgradeText.text = "短时间内再次点击空白处或发射按钮子弹静止";

            bj.addChild(upgradeText);
            this.addChild(this.bj);
            this.addChild(this.fashe);
            /**新手指导 */
            // this.addChild(this.Newarrow);
            // this.removeChild(this.Newarrow1);
            this.Newarrow.visible = true;
            this.Newarrow1.visible = false;
            //  this.addChild(this.Newarrow);
            // Tween.get(this.Newarrow).to({alpha:0},1000);  
            egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁    


            // egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);

        }
      else  if (this.upgradeNumber2 == 3 && this.upgradeNumber3 == 0 && this.jinbicishu == 0) {
            this.upgradeNumber3 = 3;
            tanChuang=1;
            this.upgradeNumber4 = 1;
            this.jinbicishu = 3;
      
            bj.addChild(text3)
            upgradeText.text = "上方分数加1，\n下方子弹补充1\n每经过一次反弹，\n分数和子弹会再加1"
            var text: egret.TextField = new egret.TextField();
            text.text = "分数加1";
            text.textColor = 0x00ff00;
            text.size = 50;
            text.width = 400;
            text.x = 240 - text.textWidth / 2;
            text.y = 40 - text.textHeight / 2;
            var text2: egret.TextField = new egret.TextField();
            text2.text = "子弹数加1";
            text2.textColor = 0x00ff00;
            text2.size = 50;
            text2.width = 400;
            text2.x = 350;
            text2.y = 1055;

            bj.addChild(text);
            bj.addChild(text2);
            bj.addChild(upgradeText);
            //this.bj.visible=true;
            this.addChild(this.bj);
            this.addChild(this.fashe);
            /**新手指导 */
            // this.addChild(this.Newarrow);
            // this.removeChild(this.Newarrow1);
            this.Newarrow.visible = true;
            this.Newarrow1.visible = false;
            //this.addChild(this.Newarrow);
            egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁    


            /**新手指导的箭头指示 */
            this.Newjiantou.visible = false;


            // egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
            //Tween.get(this.Newarrow).to({alpha:1},800);           
        }
     else   if (this.upgradeNumber2 == 4 && this.upgradeNumber3 == 0) {
            this.upgradeNumber3 = 4;
            tanChuang=1;
            this.upgradeNumber4 = 1;
           // bj.addChild(text3)
            upgradeText.text = "右下方第二个按钮为微调大轮盘（微调作用）的显示与隐藏即微调按钮，默认开启"

            bj.addChild(upgradeText);
          //  bj.addChild(text3);
            this.addChild(this.bj);
            // this.addChild(this.btn);
            this.addChild(this.fashe);

            this.Newarrow.visible = false;
            this.Newarrow1.visible = true;
            //this.addChild(this.Newarrow);
            egret.Tween.get(this.Newarrow1, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁    


        }
      else  if (this.upgradeNumber2 == 51 && this.upgradeNumber3 == 0) {
            this.upgradeNumber3 = 5;
            tanChuang=1;
            this.upgradeNumber4 = 1;//
            bj.addChild(text3)

            upgradeText.text = "爆炸道具：效果为：打出后点击第二次可以把自己附近的基础球炸掉。每经过一次反弹，得到的道具数量会加1"
            bj.addChild(upgradeText);
            this.addChild(this.bj);
            this.addChild(this.fashe);
            /**新手指导 */
            // this.addChild(this.Newarrow);
            // this.removeChild(this.Newarrow1);
            this.Newarrow.visible = true;
            this.Newarrow1.visible = false;
            egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁    


            // egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
        }
     else   if (this.upgradeNumber2 == 52 && this.upgradeNumber3 == 0) {
            this.upgradeNumber3 = 5;
            tanChuang=1;
            this.upgradeNumber4 = 1;//新手引导
            bj.addChild(text3)

            upgradeText.text = "放大道具：效果为：打出后的子弹很大。每经过一次反弹，得到的道具数量会加1"
            bj.addChild(upgradeText);
            this.addChild(this.bj);
            this.addChild(this.fashe);
            /**新手指导 */
            // this.addChild(this.Newarrow);
            // this.removeChild(this.Newarrow1);
            this.Newarrow.visible = true;
            this.Newarrow1.visible = false;
            egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁    


            // egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
        }
      else  if (this.upgradeNumber2 == 53 && this.upgradeNumber3 == 0) {
            this.upgradeNumber3 = 5;
            tanChuang=1;
            this.upgradeNumber4 = 1;//新手引导
            bj.addChild(text3)
            var daojuText: egret.TextField = new egret.TextField();
            daojuText.width = 400;
            daojuText.height = 400;
            daojuText.x = 140;
            daojuText.y = 330;
            daojuText.textColor = 0x00c4a851;
            daojuText.size = 32;
            daojuText.textAlign = egret.HorizontalAlign.CENTER;



            daojuText.text = "触发道具：打出子弹后点击第二次可以停留在舞台成为触发球。效果为：打出的子弹如果从触发球内穿过然后碰到基础球可以把基础球消掉并且触发球触发次数减1，触发球可触发次数为3，触发次数为0时，触发球消失。每经过一次反弹，得到的道具数量会加1"

            bj.addChild(daojuText);
            this.addChild(this.bj);
            this.addChild(this.fashe);
            /**新手指导 */
            // this.addChild(this.Newarrow);
            // this.removeChild(this.Newarrow1);
            this.Newarrow.visible = true;
            this.Newarrow1.visible = false;
            egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁   



        }
     else   if (this.upgradeNumber2 == 54 && this.upgradeNumber3 == 0) {
            this.upgradeNumber3 = 5;
            tanChuang=1;
            this.daojutishi = 1;
            this.upgradeNumber4 = 1;//新手引导
            bj.addChild(text3)

            upgradeText.text = "重力道具：效果为：打出子弹后点击第二次子弹会垂直下落，途中如果碰到基础球可以把基础球消失。每经过一次反弹，得到的道具数量会加1"
            bj.addChild(upgradeText);
            this.addChild(this.bj);
            this.addChild(this.fashe);
            /**新手指导 */
            // this.addChild(this.Newarrow);
            // this.removeChild(this.Newarrow1);
            this.Newarrow.visible = true;
            this.Newarrow1.visible = false;
            egret.Tween.get(this.Newarrow, { loop: true }).to({ alpha: 0 }, 200).to({ alpha: 1 }, 200); //颜色闪烁    


        }

      else  if (this.upgradeNumber2 == 6 && this.upgradeNumber3 == 0) {
            this.upgradeNumber3 = 6;
            tanChuang=1;

            // var btnStart: MButton = new MButton(new MImage("btnStart_png"), new MImage("btnStart_png"));

            // this.controlGun.close();
            // btnStart.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            // btnStart.x = (this.stageWidth - btnStart.width) >> 1;
            // btnStart.y = 650;

            var bj2 = new MImage("over2Panel_png");
            this.bj = bj2;
            var btn: MButton = new MButton(new MImage("btnStart_png"), new MImage("btnStart_png"));
            this.btn = btn;

            btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.zhengshiStart, this);
            btn.x = (this.stageWidth - btn.width) >> 1;
            btn.y = 650;

            this.addChild(this.bj);
            this.addChild(btn);
            /**新手指导 */
            // this.removeChild(this.Newarrow);
            // this.removeChild(this.Newarrow1);
            // this.Newarrow.visible = false;
            // this.Newarrow1.visible = false;
            this.removeChild(this.Newarrow);
            this.removeChild(this.Newarrow1);
            /**新手指导结束 */
            //     egret.localStorage.setItem("xinshouyindao", "true");
            //     console.log("反馈技术附件该接口" + egret.localStorage.getItem("xinshouyindao"));
            // }
        }

        else {
            // this.removeChild(this.Newarrow);
            // this.removeChild(this.Newarrow1);
            return;
        }
    }
    private zhengshiStart() {

        //this.removeChild(UpgradeTishi);
        // this.removeChild(this.Newarrow);
        // this.removeChild(this.Newarrow1);
        /**新手指导 */
        //  this.empty1();//如果场景里存在金币，清除金币
        this.empty();
        this.count = 0;
        this.score = this.count;
        this.updateScore();
        this.upgradeNumber = 1;
        this.shareNum = 0;
        this.gun.bullet = 10;
        this.gun.updateNum((this.gun.bullet));
        this.BaozhaCount = 0; this.Textbaozha.text = this.BaozhaCount.toString();
        this.ChufaCount = 0; this.Textchufa.text = this.ChufaCount.toString();
        this.ZhongliCount = 0; this.Textzhongli.text = this.ZhongliCount.toString();
        this.FangdaCount = 0; this.Textfangda.text = this.FangdaCount.toString();
        this.onClick()

        this.sffaqiu = false;
        this.shangdan1();
        this.my_ball = [];
        this.boomNum = 0;
        this.m_PropManager.allProps = [];
        this.isOver = 0;
        this.upgradeNumber = 1;


        this.my_strikeBall = [];
        this.Striketime.chufashuzi = 3;
        this.Striketime.x = -100;
        this.Striketime.y = -100;
        this.Collidetime.x = -150;
        this.Collidetime.y = -150;
        this.overValue = 1;
        this.sendMsg(GameData.score);

    }

    /**选关界面继续按钮点击事件*/
    private onClick() {

        this.removeChild(this.bj);
        this.removeChild(this.btn);
        if (this.upgradeNumber3 != 0) {
            this.upgradeNumber3 = 0;
            this.upgradeNumber2 = 0;
            tanChuang=0;
        }
    }

    /**激光道具粒子特效 */
    public xx(X: number, y: number) {
        SoundControl.getIns().addItem(MUSIC_CL);
        SoundControl.getIns().play(MUSIC_CL, 0, 1);
        var texture = RES.getRes("JiGuang_1_png");
        var config = RES.getRes("JiGuang_1_json");
        var particleSys = new particle.GravityParticleSystem(texture, config);
        particleSys.x = X - 330;
        particleSys.y = y - 220;
        this.addChild(particleSys);
        particleSys.start(300);

        var text = RES.getRes("JiGuang_1_png");
        var conf = RES.getRes("JiGuang_1_json");
        var particleSy = new particle.GravityParticleSystem(text, conf);
        particleSy.x = X + 340;
        particleSy.y = y + 217;
        particleSy.rotation = -180;
        this.addChild(particleSy);
        particleSy.start(300);

        /**新手指导 */
        if (tishi == 3) {
            //this.removeChild(this.Newjiantou);
            this.Newjiantou.x = 40;
            this.Newjiantou.y = 380;
            egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
        }
        else if (tishi == 5) {
            this.Newjiantou.x = 280;
            this.Newjiantou.y = 530;
            egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
        }

        else {
            this.Newjiantou.visible = false;
        }

    }


    public jiguangmei() {
        this.removeChild(this.Ball);
    }


    /**金币播放动画以及移动 */
    public goldFrameAnimation(point: egret.Point) {

        var texture2mc = RES.getRes("Gold_png");
        var data2mc = RES.getRes("Gold_json");
        let mcFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data2mc, texture2mc);
        let mc: egret.MovieClip = new egret.MovieClip(mcFactory.generateMovieClipData("Gold"));
        this.addChild(mc);
        mc.gotoAndPlay("Gold", 1);//"A" : Boom -1 ： 循环播放				
        mc.x = point.x - 60;
        mc.y = point.y - 60;
        mc.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
            this.removeChild(mc);
        }, this);

        //Tween动画
        var tw = egret.Tween.get(mc);
        tw.to({ x: 50, y: 50 }, 700);

    }

    /**改变颜色 */
    private changeColor() {
        // this.gun.ball.visible = false;
        // this.gun.redball.visible = false;
        // this.gun.magnify.visible = false;
        // this.gun.gravity.visible = false;
        // this.gun.strike.visible = false;
        // if (this.NowBullet.objkind == 301) {
        //     this.gun.ball.visible = true;
        // }
        // else if (this.NowBullet.objkind == 102) {
        //     this.gun.redball.visible = true;
        // }
        // else if (this.NowBullet.objkind == 103) {
        //     this.gun.magnify.visible = true;
        // } else if (this.NowBullet.objkind == 104) {
        //     this.gun.gravity.visible = true;
        // } else if (this.NowBullet.objkind == 105) {
        //     this.gun.strike.visible = true;
        // }
    }
    /**改变颜色 */
    private changeColor1() {
        // this.gun.ball.visible = false;
        // this.gun.redball.visible = false;
        // this.gun.magnify.visible = false;
        // this.gun.gravity.visible = false;
        // this.gun.strike.visible = false;
        // if (this.NowBullet1.objkind == 301) {
        //     this.gun.ball.visible = true;
        // }
        // else if (this.NowBullet1.objkind == 102) {
        //     this.gun.redball.visible = true;
        // }
        // else if (this.NowBullet1.objkind == 103) {
        //     this.gun.magnify.visible = true;
        // } else if (this.NowBullet1.objkind == 104) {
        //     this.gun.gravity.visible = true;
        // } else if (this.NowBullet1.objkind == 105) {
        //     this.gun.strike.visible = true;
        // }
    }
    /**改变子弹 */
    public changeBullet() {
        this.NowBullet1 = this.fakeBullet;
        this.changeColor1();
    }

    /**碰撞 */
    protected onHitBegin(evt): void {
        var chishu = 0;
        var lizizhu = new egret.Point(0, 0)
        var zhonglei = -1;
        var ball: p2.Body;
        //将动态子弹赋值给ObjOne    静态道具、子弹赋值给ObjTwe
        if (evt.bodyA.userData.data.objkind == 301) {
            var objOne: py2Obj.basicObj = evt.bodyA.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyB.userData.data;
        }
        else if (evt.bodyB.userData.data.objkind == 301) {
            var objOne: py2Obj.basicObj = evt.bodyB.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyA.userData.data;
        }
        if (evt.bodyA.userData.data.objkind == 302) {
            var objOne: py2Obj.basicObj = evt.bodyA.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyB.userData.data;
        }
        else if (evt.bodyB.userData.data.objkind == 302) {
            var objOne: py2Obj.basicObj = evt.bodyB.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyA.userData.data;
        }
        else if (evt.bodyA.userData.data.objkind == 102) {
            var objOne: py2Obj.basicObj = evt.bodyA.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyB.userData.data;
        }
        else if (evt.bodyB.userData.data.objkind == 102) {
            var objOne: py2Obj.basicObj = evt.bodyB.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyA.userData.data;
        }
        else if (evt.bodyA.userData.data.objkind == 103) {
            var objOne: py2Obj.basicObj = evt.bodyA.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyB.userData.data;
        }
        else if (evt.bodyB.userData.data.objkind == 103) {
            var objOne: py2Obj.basicObj = evt.bodyB.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyA.userData.data;
        } else if (evt.bodyA.userData.data.objkind == 104) {
            var objOne: py2Obj.basicObj = evt.bodyA.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyB.userData.data;
        }
        else if (evt.bodyB.userData.data.objkind == 104) {
            var objOne: py2Obj.basicObj = evt.bodyB.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyA.userData.data;
        }
        else if (evt.bodyA.userData.data.objkind == 105) {
            var objOne: py2Obj.basicObj = evt.bodyA.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyB.userData.data;
        }
        else if (evt.bodyB.userData.data.objkind == 105) {
            var objOne: py2Obj.basicObj = evt.bodyB.userData.data;
            var objTwe: py2Obj.basicObj = evt.bodyA.userData.data;
        }
        //判断发射的子弹是普通的还是爆炸
        if (objOne.objkind == 301) {//普通子弹
            var bullet = objTwe.getCollision(objOne);
            if (bullet != null) {
                // this.getPoint(bullet);
                this.my_ball.push(bullet);
            }
            objOne.getCollision(objTwe);
            /*if (objTwe.objkind == 400) {
                // if (this.Collidetime.shuzi > 0) {//如果碰到一个球时（数字>0）
                //     // this.count += (this.Collidetime.shuzi + 1);//分翻倍
                //     // this.score = this.count;
                //     // this.updateScore();
                //     // this.gun.bullet = (this.gun.bullet) + ((this.Collidetime.shuzi) + 1);//自己的炮弹也是翻倍
                //     // this.gun.updateNum(this.gun.bullet)//更新炮弹
                // } else {
                //     // this.count += 1;
                //     // this.score = this.count;
                //     // this.updateScore();
                // this.gun.updateNum(++(this.gun.bullet));
                // }
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 0;
                this.liziy(lizizhu, zhonglei, chishu);
                zhonglei = 1;
            }
            if (objTwe.objkind == 401) {
                // this.propCount = this.Collidetime.shuzi + 1;
                // this.count += 0;
                // this.score = this.count;
                // this.NowBullet1 = this.boomBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 5;
            }
            if (objTwe.objkind == 402) {
                // if (this.Collidetime.shuzi > 0) {
                // this.propCount = this.Collidetime.shuzi + 1;
                // // }
                // this.count += 0;
                // this.score = this.count;
                // this.NowBullet1 = this.MagnifyBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 3;
                //   this.propCount = 1;

            }

            if (objTwe.objkind == 404) {
                // this.count += 0;
                // this.score = this.count;
            }
            if (objTwe.objkind == 405) {
                // this.propCount = this.Collidetime.shuzi + 1;
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.gravityBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 4;
            }
            if (objTwe.objkind == 406) {

                // this.count += 0;
                // this.score = this.count;
                // // this.propCount = 1;
                // this.NowBullet1 = this.strikeBullet;
                this.isChanger = 1;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 2;
            }
            if (objTwe.objkind == 108) {
                this.Striketime.updateNum(--(this.Striketime.chufashuzi));
                this.strikeChange();
                if (this.Striketime.chufashuzi == 0) {//碰撞满3次后消失

                    var bian1 = this.my_strikeBall.indexOf(objTwe);
                    this.my_strikeBall[bian1].removeBasicbullet(objTwe);
                    this.my_strikeBall.splice(bian1, 1);
                    this.removeChild(this.Striketime);
                    this.Striketime.chufashuzi = 3;


                }

            }
            if (this.isStrike == 1) {
                if (objTwe.objkind == 100) {
                    var bian = this.my_ball.indexOf(objTwe);
                    this.my_ball[bian].removeBasicbullet(objTwe);
                    this.my_ball.splice(bian, 1);
                }
            }*/
            if (objTwe.objkind == 100) {
                this.Collidetime.shuzi++;
                this.Collidetime.updateNum(this.Collidetime.shuzi);//更改碰撞显示次数
                console.log(this.Collidetime.shuzi);
                ++this.jiaQiuCount;  //9999 
            }
            //碰撞到球
            if(objTwe.objkind==500)
            {
                if(this.istop&&this.playTwoHp>0)
                {
                    this.playOneHp--;
                }
                if(!this.istop&&this.playOneHp>0)
                {
                    this.playTwoHp--;
                }
            }

           //碰撞到蓝色砖块
           if(objTwe.objkind==600)
           {
                   objTwe.m_num--;
                 this.Collidetime.updateNum(++this.Collidetime.shuzi);//更改碰撞显示次数
                ++this.jiaQiuCount;
                  /* if(this.istop)
                   {
                    this.zhuanTXT.text=this.zhuan.m_num.toString();
                   }
                   else if(!this.istop)
                   {
                    this.zhuanTopTXT.text=this.zhuanTop.m_num.toString();
                   }*/
                   if(objTwe.m_num<=0)
                   {
                      objTwe.setPostion(-600,-600);
                   }
           }
        }
       /* else if(objOne.objkind == 302)
        {
            var bullet = objTwe.getCollision(objOne);
            if (bullet != null) {
                // this.getPoint(bullet);
                this.my_ball.push(bullet);
            }
            objOne.getCollision(objTwe);
            if (objTwe.objkind == 100) {
                this.Collidetime.shuzi++;
                this.Collidetime.updateNum(this.Collidetime.shuzi);//更改碰撞显示次数
                console.log(this.Collidetime.shuzi);
                ++this.jiaQiuCount;  //9999 
            }
            //碰撞到球
            if(objTwe.objkind==500)
            {
                if(this.istop&&this.playTwoHp>0)
                {
                    this.playOneHp--;
                }
                if(!this.istop&&this.playOneHp>0)
                {
                    this.playTwoHp--;
                }
            }

           //碰撞到蓝色砖块
           if(objTwe.objkind==600)
           {
                   objTwe.m_num--;
                   if(this.istop)
                   {
                    this.zhuanTXT.text=this.zhuan.m_num.toString();
                   }
                   else if(!this.istop)
                   {
                    this.zhuanTopTXT.text=this.zhuanTop.m_num.toString();
                   }
                   if(objTwe.m_num<=0)
                   {
                      objTwe.setPostion(-600,-600);
                   }
           }
    }*/
        else if (objOne.objkind == 103) {  //放大弹
            // objTwe.getCollision(objOne);
            // objOne.getCollision(objTwe);
            var bullet = objTwe.getCollision(objOne);
            if (bullet != null) {
                // this.getPoint(bullet);
                this.my_ball.push(bullet);
            }
            objOne.getCollision(objTwe);
            if (objTwe.objkind == 400) {
                // this.count += 1;
                // this.score = this.count;
                // this.updateScore();
                // this.gun.updateNum(++(this.gun.bullet));
                // // if (this.propCount == 0) {//道具数量为0 才能更改子弹
                //   this.changeBullet();
                // // }
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 0;
                this.liziy(lizizhu, zhonglei, chishu);
                zhonglei = 1;
                if (this.gun.bullet <= 0)    //111111111
                {
                    this.isOver = 1;
                    this.over();
                }
            }
            else if (objTwe.objkind == 401) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.boomBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 5;
            }
            else if (objTwe.objkind == 403) {
                // this.count += 0;
                // this.score = this.count;
                this.my_ball = [];
            }
            else if (objTwe.objkind == 404) {
                // this.count += 0;
                // this.score = this.count;
            }
            else if (objTwe.objkind == 402) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.MagnifyBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 3;
            } else if (objTwe.objkind == 405) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.gravityBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 4;
            } else if (objTwe.objkind == 406) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.strikeBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 2;
            } else if (objTwe.objkind == 100) {
                this.Collidetime.updateNum(++(this.Collidetime.shuzi));//更改碰撞显示次数
                ++this.jiaQiuCount;  //9999

            } else if (objTwe.objkind == 108) {
                this.Striketime.updateNum(--(this.Striketime.chufashuzi));
                this.strikeChange();
                if (this.Striketime.chufashuzi == 0) {//碰撞满3次后消失

                    var bian1 = this.my_strikeBall.indexOf(objTwe);
                    this.my_strikeBall[bian1].removeBasicbullet(objTwe);
                    this.my_strikeBall.splice(bian1, 1);

                    this.removeChild(this.Striketime);
                    this.Striketime.chufashuzi = 3;


                }
            }
            else if (this.isStrike == 1) {
                if (objTwe.objkind == 100) {
                    var bian = this.my_ball.indexOf(objTwe);
                    this.my_ball[bian].removeBasicbullet(objTwe);
                    this.my_ball.splice(bian, 1);
                }
            }
            // else {
            //     if (this.propCount == 0) {//道具数量为0 才能更改子弹
            //         this.changeBullet();
            //     }
            // }

        } else if (objOne.objkind == 102) {//爆炸弹
            var bullet = objTwe.getCollision(objOne);
            if (bullet != null) {
                // this.getPoint(bullet);
                this.my_ball.push(bullet);
            }
            objOne.getCollision(objTwe);
            if (objTwe.objkind == 400) {
                // this.count += 1;
                // this.score = this.count;
                // this.updateScore();
                // this.gun.updateNum(++(this.gun.bullet));
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 0;
                this.liziy(lizizhu, zhonglei, chishu);
                zhonglei = 1;
                if (this.gun.bullet <= 0)    //111111111
                {
                    this.isOver = 1;
                    this.over();
                }
            }
            if (objTwe.objkind == 401) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.boomBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 5;
            }
            if (objTwe.objkind == 402) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.MagnifyBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 3;
            }
            if (objTwe.objkind == 405) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.gravityBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 4;
            }
            if (objTwe.objkind == 406) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.strikeBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 2;
            }
            if (objTwe.objkind == 404) {
                // this.count += 0;
                // this.score = this.count;
            }
            if (objTwe.objkind == 100) {
                this.Collidetime.updateNum(++(this.Collidetime.shuzi));//更改碰撞显示次数
                ++this.jiaQiuCount;  //9999

            }
            if (objTwe.objkind == 108) {
                this.Striketime.updateNum(--(this.Striketime.chufashuzi));
                this.strikeChange();
                if (this.Striketime.chufashuzi == 0) {//碰撞满3次后消失

                    var bian1 = this.my_strikeBall.indexOf(objTwe);
                    this.my_strikeBall[bian1].removeBasicbullet(objTwe);
                    this.my_strikeBall.splice(bian1, 1);

                    this.removeChild(this.Striketime);
                    this.Striketime.chufashuzi = 3;


                }
            }
            if (this.isStrike == 1) {
                if (objTwe.objkind == 100) {
                    var bian = this.my_ball.indexOf(objTwe);
                    this.my_ball[bian].removeBasicbullet(objTwe);
                    this.my_ball.splice(bian, 1);
                }
            }
        } else if (objOne.objkind == 104) {//重力球
            var bullet = objTwe.getCollision(objOne);
            if (bullet != null) {
                // this.getPoint(bullet);
                this.my_ball.push(bullet);
            }
            objOne.getCollision(objTwe);
            if (objTwe.objkind == 400) {
                // this.count += 1;
                // this.score = this.count;
                // this.updateScore();
                // this.gun.updateNum(++(this.gun.bullet));
                // if (this.propCount == 0) {//道具数量为0 才能更改子弹
                //     this.changeBullet();
                // }
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 0;
                this.liziy(lizizhu, zhonglei, chishu);
                zhonglei = 1;
                if (this.gun.bullet <= 0)    //111111111
                {
                    this.isOver = 1;
                    this.over();
                }
            }
            else if (objTwe.objkind == 401) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.boomBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 5;
            }
            else if (objTwe.objkind == 403) {
                // this.count += 0;
                // this.score = this.count;
                this.my_ball = [];
            }
            else if (objTwe.objkind == 405) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.gravityBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 4;
            } else if (objTwe.objkind == 404) {
                // this.count += 0;
                // this.score = this.count;
            }
            else if (objTwe.objkind == 402) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.MagnifyBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 3;
            } else if (objTwe.objkind == 406) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.strikeBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 2;
            }
            else if (objTwe.objkind == 100) {
                this.Collidetime.updateNum(++(this.Collidetime.shuzi));//更改碰撞显示次数
                ++this.jiaQiuCount;  //9999

            } else if (objTwe.objkind == 108) {
                this.Striketime.updateNum(--(this.Striketime.chufashuzi));
                this.strikeChange();
                if (this.Striketime.chufashuzi == 0) {//3次后消失
                    var bian1 = this.my_strikeBall.indexOf(objTwe);
                    this.my_strikeBall[bian1].removeBasicbullet(objTwe);
                    this.my_strikeBall.splice(bian1, 1);

                    this.removeChild(this.Striketime);
                    this.Striketime.chufashuzi = 3;


                }
            } else if (objTwe.objkind == 100) {
                if (this.isStrike == 1) {
                    var bian = this.my_ball.indexOf(objTwe);
                    this.my_ball[bian].removeBasicbullet(objTwe);
                    this.my_ball.splice(bian, 1);
                }
            }
            // else {
            //     if (this.propCount == 0) {//道具数量为0 才能更改子弹
            //         this.changeBullet();
            //     }
            // }
            if (this.bianliang == 1) {
                if (objTwe.objkind == 100) {
                    // this.my_ball[0].removeBasicbullet(objTwe);
                    // this.my_ball.splice(0, 1);
                    var bian2 = this.my_ball.indexOf(objTwe);//查到下标值
                    this.my_ball[bian2].removeBasicbullet(objTwe);
                    this.my_ball.splice(bian2, 1);
                }
            }

        } else if (objOne.objkind == 105) {//触发球
            var bullet = objTwe.getCollision(objOne);
            if (bullet != null) {
                // this.getPoint(bullet);
                this.my_ball.push(bullet);
            }
            objOne.getCollision(objTwe);
            if (objTwe.objkind == 400) {
                // this.count += 1;
                // this.score = this.count;
                // this.updateScore();
                // this.gun.updateNum(++(this.gun.bullet));
                // if (this.propCount == 0) {//道具数量为0 才能更改子弹
                //     this.changeBullet();
                // }
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 0;
                this.liziy(lizizhu, zhonglei, chishu);
                zhonglei = 1;
                if (this.gun.bullet <= 0)    //111111111
                {
                    this.isOver = 1;
                    this.over();
                }
            }
            else if (objTwe.objkind == 401) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.boomBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 5;
            }
            else if (objTwe.objkind == 402) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.MagnifyBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 3;
            }
            else if (objTwe.objkind == 405) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.gravityBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 4;
            }
            else if (objTwe.objkind == 406) {
                // this.count += 0;
                // this.score = this.count;
                // this.propCount = 1;
                // this.NowBullet1 = this.strikeBullet;
                lizizhu = new egret.Point(objTwe.m_body.position[0], objTwe.m_body.position[1])
                chishu = this.Collidetime.shuzi
                zhonglei = 2;
            }
            else if (objTwe.objkind == 404) {
                this.count += 0;
                this.score = this.count;
            }
            else if (objTwe.objkind == 100) {
                this.Collidetime.updateNum(++(this.Collidetime.shuzi));//更改碰撞显示次数
                ++this.jiaQiuCount;  //9999

            }
            // else {
            //     if (this.propCount == 0) {//道具数量为0 才能更改子弹
            //         this.changeBullet();

            //     }
            // }


        }
        // if (objTwe.objkind == 200 || objTwe.objkind == 201) {
        if (this.propCount <= 0 && this.isChanger == 0) {//道具数量为0 才能更改子弹
            this.changeBullet();

        }
        // }
        // if (this.boomNum >= 4) {//当前子弹操作结束 第五发子弹才会是爆炸弹
        //     if (this.NowBullet1 != null) {

        //         if (this.NowBullet1.objkind == 103) {
        //             this.NowBullet1 = this.MagnifyBullet;
        //         } else if (this.NowBullet1.objkind == 102) {
        //             this.NowBullet1 = this.boomBullet;
        //         } else if (this.NowBullet1.objkind == 104) {
        //             this.NowBullet1 = this.gravityBullet;
        //         } else if (this.NowBullet1.objkind == 105) {
        //             this.NowBullet1 = this.strikeBullet;
        //         }
        //         else {
        //             this.NowBullet1 = this.boomBullet;
        //             this.boomNum = 0;
        //         }
        //     }
        //     if (this.boomNum == 4 && this.NowBullet1 == null) {//第五发子弹改为爆炸子弹
        //         this.NowBullet1 = this.boomBullet;
        //         this.boomNum = 0;
        //     }

        //     this.isChanger = 1;
        // }

        // if (this.boomNum == 5) {
        //     this.NowBullet1 = this.boomBullet;
        //    this.boomNum = 0;
        //     this.isChanger = 1;
        // }
        // this.changeColor();//改变下个球的颜色 
        // if (this.NowBullet1 != null) {
        //     this.changeColor1();//改变下个球的颜色 
        //     // if(this.NowBullet1.objkind==103)
        //     // {
        //     //     this.e=45;
        //     // }
        //     // else
        //     // {
        //     //     this.e=13;
        //     // }
        // }
        this.count += 0;
        this.score = this.count;
        if (zhonglei != -1) {//44444&&this.jiaQiuCount>0
            console.log("**********" + zhonglei)
            this.liziy(lizizhu, zhonglei, this.jiaQiuCount);
        }
        if (objTwe.objkind == 200 || objTwe.objkind == 201) {//碰到墙销毁子弹
            if(this.huiheNum>=2)
            {
                this.istop=!this.istop;
                this.qiehuan=false;
                this.huiheNum=0;
            }
            this.Collidetime.shuzi = 0;
            
            this.Collidetime.txtNum1.visible=false;
            this.fashe.visible=true;
            this.adjustment.visible=true;
            if(tishi==5||tishi==6||tishi==7||tishi==8){
            tanChuang=2;
            }
            this.NowBullet.m_body.velocity = [0, 0];
            this.NowBullet.setPostion(-10110, -14547);
            this.NowBullet.isRun == false;
            if (this.isOver == 0) {
                if (this.gun.bullet <= 0 && this.NowBullet.isRun == false && this.Collidetime.shuzi <= 0) {
                    this.isOver = 1;
                    this.over();
                }
                else if (this.gun.bullet <= 0 && this.NowBullet.isRun == false) {
                    this.isOver = 1;
                    this.over();
                }
                else if (this.gun.bullet <= 0) {
                    this.isOver = 1;
                    this.over();
                }
            }
        }
        if (this.gun.bullet <= 0 && this.NowBullet.isRun == false && zhonglei != 1) {
            this.isOver = 1;
            this.over();
        }

        if (this.m_PropManager.m_props1.length > 0) {
            if (this.m_PropManager.m_props1[0].objkind == 400) {
                this.m_PropManager.removePorp1(this.m_PropManager.m_props1[0]);
            }
        }
            tanChuang=0;
    }
    public judgeOver() {
        this.NowBullet.runEnd1();
        this.isStrike = 1;
    }
    public strikeChange() {
        this.OverTimer = new egret.Timer(100, 1);
        this.OverTimer.start();//开始计时
        this.OverTimer.addEventListener(egret.TimerEvent.TIMER, this.judgeOver, this);//计时中事件
    }
    // /**判断是否死亡 */
    // public judgeOver() {
    //     if (this.gun.bullet <= 0 && this.NowBullet.isRun == false) {
    //         this.over();
    //     }
    // }

    // //计算与重力球接触的基本球
    // public gravityResult(X: number, Y: number) {
    //     for (var i = 0; i < this.my_ball.length; i++) {
    //         let p1 = new egret.Point;
    //         p1.x = X;
    //         p1.y = Y;
    //         let p2 = new egret.Point;
    //         p2.x = this.my_ball[i].m_body.position[0];
    //         p2.y = this.my_ball[i].m_body.position[1];
    //         //判断距离  小于一定距离销毁球
    //         if (this.zhonglijisuan(p1, p2) && this.my_ball[i].objkind == 100) {
    //             this.my_ball[i].removeBasicbullet(this.my_ball[i]);
    //             this.my_ball.splice(i, 1);
    //             i--;
    //         }

    //     }
    //     // this.removeEventListener(egret.Event.ENTER_FRAME, this.chuanweizhi, this);
    // }

    public laserResult(X: number, Y: number) {//激光道具销毁效果运算
        this.xx(X, Y);//激光帧动画 预留
        for (var i = 0; i < this.my_ball.length; i++) {
            let p1 = new egret.Point;
            p1.x = X;
            p1.y = Y;
            let p2 = new egret.Point;
            p2.x = this.my_ball[i].m_body.position[0];
            p2.y = this.my_ball[i].m_body.position[1];
            //判断距离  小于一定距离销毁球
            if (this.getRightball(p1, p2) && this.my_ball[i].objkind == 100) {
                this.my_ball[i].removeBasicbullet(this.my_ball[i]);
                this.my_ball.splice(i, 1);
                i--;
            }

        }
        if (this.propCount == 0) {
            this.changeBullet();
        }
    }
    public bombBlasts(X: number, Y: number) {
        this.frameAnimation(X, Y);

        //销毁子弹判断
        for (var i = 0; i < this.my_ball.length; i++) {
            let p1 = new egret.Point;
            p1.x = X;
            p1.y = Y;
            let p2 = new egret.Point;
            p2.x = this.my_ball[i].m_body.position[0];
            p2.y = this.my_ball[i].m_body.position[1];
            //判断距离  小于一定距离销毁球
            if (this.getDisPTOP(p1, p2) && this.my_ball[i].objkind == 100) {
                this.my_ball[i].removeBasicbullet(this.my_ball[i]);
                this.my_ball.splice(i, 1);
                i--;
            }

        }
        //销毁道具判断
        // var my_prop = this.m_PropManager.m_props1;
        var my_prop = this.m_PropManager.allProps;
        for (var i = 0; i < my_prop.length; i++) {
            let p1 = new egret.Point;
            p1.x = X;
            p1.y = Y;
            let p2 = new egret.Point;
            p2.x = my_prop[i].m_body.position[0];
            p2.y = my_prop[i].m_body.position[1];
            //判断距离  小于一定距离销毁球
            if (this.getDisPTOP(p1, p2) && my_prop[i].objkind == 401) {//爆炸道具
                this.m_PropManager.removePorp1(this.m_PropManager.allProps[i]);
                // this.m_PropManager.m_props1.splice(i, 1);
                // i--;
            }
            if (this.getDisPTOP(p1, p2) && my_prop[i].objkind == 402) {//增大道具
                this.m_PropManager.removePorp1(this.m_PropManager.allProps[i]);
            }
            if (this.getDisPTOP(p1, p2) && my_prop[i].objkind == 404) {//激光道具
                this.m_PropManager.removePorp1(this.m_PropManager.allProps[i]);
            }
            if (this.getDisPTOP(p1, p2) && my_prop[i].objkind == 405) {//重力道具
                this.m_PropManager.removePorp1(this.m_PropManager.allProps[i]);
            }
            if (this.getDisPTOP(p1, p2) && my_prop[i].objkind == 406) {//重力道具
                this.m_PropManager.removePorp1(this.m_PropManager.allProps[i]);
            }

            if (this.getDisPTOP(p1, p2) && my_prop[i].objkind == 400) {//基本 金币道具
                this.m_PropManager.removePorp(this.m_PropManager.allProps[i]);
            }


        }
        if (this.propCount == 0) {
            this.changeBullet();
        }
        this.changeColor();

    }
    /**爆炸球碰到金币 */
    public crashGold() {
        if (this.propCount == 0) {
            this.changeBullet();
        }
        this.changeColor();
    }
    /**计算点到点距离 */
    public getDisPTOP(P1: egret.Point, p2: egret.Point) {
        var num1 = (P1.x - p2.x) * (P1.x - p2.x);
        var num2 = (P1.y - p2.y) * (P1.y - p2.y);
        var num = Math.sqrt((num1 + num2));
        var bool = false;
        if (num <= 130) {
            bool = true;
        }
        return bool;
    }
    /**符合激光效果计算 */
    public getRightball(P1: egret.Point, p2: egret.Point) {
        var bool = false;
        if (p2.y > ((P1.y) - 20) && p2.y < ((P1.y) + 30)) {
            bool = true;
        }
        return bool;
    }
    // /**符合重力球的效果计算 */
    // public zhonglijisuan(P1: egret.Point, p2: egret.Point) {
    //     var bool = false;
    //     if (p2.y - P1.y <= 80 && p2.x > P1.x - 40 && p2.x < P1.x + 40) {// P1.x > p2.x - 30 && P1.x < p2.x + 30
    //         bool = true;
    //     }
    //     if (P1.x == -200 && P1.y == -200) {
    //         this.removeEventListener(egret.Event.ENTER_FRAME, this.position, this);
    //         console.log("操作已完成，关闭传值");
    //     }
    //     if (P1.x == -100 && P1.y == -100) {
    //         this.removeEventListener(egret.Event.ENTER_FRAME, this.position, this);
    //         console.log("操作已完成，关闭传值100");
    //     }
    //     return bool;
    // }
    protected setBallImpulse(ball: p2.Body): void {
        var x = Math.random() > 0.5 ? -5000 : 5000;
        var y = -5000 - (Math.random() * 2000);
        ball.applyImpulse([x, y], [0, 0]);
    }
    public addPoint(addpoint) {
        this.score = this.score + addpoint;
    }
    /**更新分数 */
    public updateScore(): void {

        this.txtScore.text = this.score.toString();
        this.txtScore.x = 100;
        this.txtScore.y = 25;
        this.txtScore.textColor = 0xf06f00;
        this.Collidetime.shuzi = 0;    //加分不叠加，清空前一轮碰撞数据
        this.txtScore.visible=false;
        //  this.shishi.text = "00";

    }
    /**按下*/
    protected startBackFun(pos: egret.Point): void {
        if (this.NowBullet.isRun == false) {
            if(this.istop)
            {
            this.guntop.showLine();
            }
            if(!this.istop)
            {
             this.gun.showLine();
            }
            //this.controlGun.close();
            if (pos.x < 159 && pos.x > 468 && pos.y < 712 && pos.y > 1032 || this.panshu == 0) {//按钮
                this.zhuobiao = pos;
                this.controlMove1(pos);
                this.shape.visible = true;
            }

            this.controlMove(pos);
        }
        //this.controlGun.close();
        //this.my_ball.push(this.m_PropManager.m_props[0]);
        //this.getPoint(this.m_PropManager.m_props[0]);
        if (this.gun.lineBool) {
            this.shape.visible = true;
        }
        this.shape1.visible = false;

        // if (tishi == 4 && this.upgradeNumber3 != 0) {
        // this.removeChild(this.bj);
        // this.upgradeNumber4 = 0;
        // this.upgradeNumber3 = 0;
        // this.upgradeNumber2 = 0;

        // }
        
//         if(tanChuang==2){
//  if ((tishi == 5 || tishi == 8) && this.upgradeNumber3 != 0) {
//             this.Newjiantou.visible = true;
//             this.Newjiantou.x = 360;
//             this.Newjiantou.y = 560;
//             egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
//             this.removeChild(this.bj);
//             this.upgradeNumber4 = 0;
//             this.upgradeNumber3 = 0;
//             tanChuang=0;
//             this.upgradeNumber2 = 0;
//             this.Newarrow.visible=false;
//         }
//         // console.log("weqwddbwerwrw提示" + tishi);
//         if (tishi == 6 && this.upgradeNumber3 != 0) {
//             this.Newjiantou.visible = true;
//             this.Newjiantou.x = 90;
//             this.Newjiantou.y = 460;
//             egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
//             this.removeChild(this.bj);
//             this.upgradeNumber4 = 0;
//             this.upgradeNumber3 = 0;
//             tanChuang=0;
//             this.upgradeNumber2 = 0;
//             this.Newarrow.visible=false;
//         }

//         if (tishi == 7 && this.upgradeNumber3 != 0) {
//             this.Newjiantou.visible = true;
//             this.Newjiantou.x = 360;
//             this.Newjiantou.y = 260;
//             egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
//             this.removeChild(this.bj);
//             this.upgradeNumber4 = 0;
//             this.upgradeNumber3 = 0;
//             tanChuang=0;
//             this.upgradeNumber2 = 0;
//             this.Newarrow.visible=false;
//         }
//         }
if(tanChuang==1){
      if (tishi == 2 && this.upgradeNumber3 != 0) {
            this.removeChild(this.bj);
            this.upgradeNumber4 = 3;
            this.upgradeNumber3 = 0;
            tanChuang=0;
            var timer2: egret.Timer = new egret.Timer(500, 1);
                    //注册事件侦听器
                    timer2.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.timerComFunc22, this);
                    //开始计时
                    timer2.start();
            this.upgradeNumber2 = 0;
            this.Newarrow.visible=false;
            this.Newarrow1.visible=false;
      }
    
        if (tishi == 3 && this.upgradeNumber3 != 0) {
            this.addChild(this.Newjiantou);
            this.Newjiantou.x = 360;
            this.Newjiantou.y = 560;
            this.Newjiantou.rotation = -30;
            egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);




            this.removeChild(this.bj);
            this.upgradeNumber4 = 0;
            this.upgradeNumber3 = 0;
            tanChuang=0;
            this.upgradeNumber2 = 0;
            this.Newarrow.visible=false;
            this.Newarrow1.visible=false;
        }

        if (tishi == 4 && this.upgradeNumber3 != 0) {
            this.Newjiantou.visible = true;
            this.Newjiantou.x = 60;
            this.Newjiantou.y = 210;
            egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
            this.removeChild(this.bj);
            this.upgradeNumber4 = 0;
            this.upgradeNumber3 = 0;
            tanChuang=0;
            this.upgradeNumber2 = 0;
            this.Newarrow.visible=false;
        }

        if ((tishi == 5 || tishi == 8) && this.upgradeNumber3 != 0) {
            this.Newjiantou.visible = true;
            this.Newjiantou.x = 360;
            this.Newjiantou.y = 560;
            egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
            this.removeChild(this.bj);
            this.upgradeNumber4 = 0;
            this.upgradeNumber3 = 0;
            tanChuang=0;
            this.upgradeNumber2 = 0;
            this.Newarrow.visible=false;
        }
        // console.log("weqwddbwerwrw提示" + tishi);
        if (tishi == 6 && this.upgradeNumber3 != 0) {
            this.Newjiantou.visible = true;
            this.Newjiantou.x = 90;
            this.Newjiantou.y = 460;
            egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
            this.removeChild(this.bj);
            this.upgradeNumber4 = 0;
            this.upgradeNumber3 = 0;
            tanChuang=0;
            this.upgradeNumber2 = 0;
            this.Newarrow.visible=false;
        }

        if (tishi == 7 && this.upgradeNumber3 != 0) {
            this.Newjiantou.visible = true;
            this.Newjiantou.x = 360;
            this.Newjiantou.y = 260;
            egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
            this.removeChild(this.bj);
            this.upgradeNumber4 = 0;
            this.upgradeNumber3 = 0;
            tanChuang=0;
            this.upgradeNumber2 = 0;
            this.Newarrow.visible=false;
        }


}











    }
    public updatePoint(pos: egret.Point): void {
        var r: number = 180 - Math.atan2(pos.x, pos.y) * 180 / Math.PI;
        var pit = new egret.Point();

        this.shape1.visible = true;
        this.shape1.$anchorOffsetX = this.gun.x;
        this.shape1.$anchorOffsetY = this.gun.y;
        this.shape1.x = this.gun.x;
        this.shape1.y = this.gun.y;
        this.shape1.rotation = r;



    }
    public getPoint(p: any) {
        // for (var k = 1; k <= 360; k += 3) {
        //     var pit = new egret.Point();
        //     if (p.objkind == 100) {
        //         pit.x = p.m_body.position[0] + 15 * Math.cos(k * Math.PI / 180);
        //         pit.y = p.m_body.position[1] + 15 * Math.sin(k * Math.PI / 180);
        //     }
        //     else {
        //         pit.x = p.m_body.position[0] + 30 * Math.cos(k * Math.PI / 180);
        //         pit.y = p.m_body.position[1] + 30 * Math.sin(k * Math.PI / 180);
        //     }
        //     p.pointList.push(pit);
        // }
    }
    /**找到最近的球 */
    public getRaycastProps(startx: number, starty: number, endx: number, endy: number): p2.Body {
        let mindis = 30;
        let min = 1000;
        let nearestBall = null;//最近的球
        for (let i = 0; i < this.my_ball.length; ++i) {
            let ball = this.my_ball[i];
            let zuobiao1 = new egret.Point(this.gun.x, this.gun.y);
            let zuobiao2 = new egret.Point(this.my_ball[i].m_body.position[0], this.my_ball[i].m_body.position[1]);
            let juli = egret.Point.distance(zuobiao1, zuobiao2);
            let dis = py2Obj.MathUtils.getDistanceBetweenPointAndLine(startx, starty, endx, endy, ball.m_body.position[0], ball.m_body.position[1], this);
            //   console.log("XXXXXXXXXXXXXXXXXXXX" + dis);
            if (dis < this.e + 13) {
                if (juli < min) {
                    min = juli;
                    nearestBall = this.my_ball[i];
                }
            }

        }
        if (nearestBall != null) {
            //console.log("mindis" + mindis + "zuobiao" + nearestBall.m_body.position[0] + "," + nearestBall.m_body.position[1]);
        }
        return nearestBall;
    }
    protected playcl1() {

        if (this.playpd) {
            this.playpd = false;
        }
    }
    protected controlMove(posMove: egret.Point): void {//微调
        /*
        if(this.istop)
        {
           this.g_un=this.guntop;
        }
        if(!this.istop)
        {
            this.g_un=this.gun;
        }*/
        if (Math.sqrt(Math.pow(posMove.x - 315, 2) + Math.pow(posMove.y - 875, 2)) <= this.Weitiaojuli) {//利用距离判断微调轮盘大小的接触面
            this.playpd = true;//控制声音
            this.faguang = true;
            if (this.zhuobiao != null && this.NowBullet.isRun == false) {
                if (posMove.y < 886 && posMove.x >= 319) {
                    if (posMove.x < this.zhuobiao.x || posMove.y < this.zhuobiao.y) {
                        this.rr -= 0.1; this.faan.rotation -= 0.6;

                    }
                    if (posMove.x > this.zhuobiao.x || posMove.y > this.zhuobiao.y) {
                        this.rr += 0.1; this.faan.rotation += 0.6;

                    }
                }
                else if (posMove.y <= 886 && posMove.x < 319) {
                    if (posMove.x < this.zhuobiao.x || posMove.y > this.zhuobiao.y) {
                        this.rr -= 0.1; this.faan.rotation -= 0.6;

                    }
                    if (posMove.x > this.zhuobiao.x || posMove.y < this.zhuobiao.y) {
                        this.rr += 0.1; this.faan.rotation += 0.6;

                    }
                }
                else if (posMove.y > 886 && posMove.x <= 319) {
                    if (posMove.x > this.zhuobiao.x || posMove.y > this.zhuobiao.y) {
                        this.rr -= 0.1; this.faan.rotation -= 0.6;

                    }
                    if (posMove.x < this.zhuobiao.x || posMove.y < this.zhuobiao.y) {
                        this.rr += 0.1; this.faan.rotation += 0.6;
                    }
                }
                else {
                    if (posMove.x > this.zhuobiao.x || posMove.y < this.zhuobiao.y) {
                        this.rr -= 0.1; this.faan.rotation -= 0.6;
                    }
                    if (posMove.x < this.zhuobiao.x || posMove.y > this.zhuobiao.y) {
                        this.rr += 0.1; this.faan.rotation += 0.6;
                    }
                }
                var aa = -Math.sin(this.rr / 57.3) * 20;
                var bb = Math.cos(this.rr / 57.3) * 20;
                this.fashezhuo = new egret.Point((aa + this.g_un.x), (bb + this.g_un.y));
                this.controlMove1(this.fashezhuo);
            }
        }
        else {
            this.playpd = false;
            this.faguang = false;
            this.fashezhuo = new egret.Point(posMove.x, posMove.y);
            this.controlMove1(this.fashezhuo);
        }
        this.zhuobiao = posMove;//{ x: posMove.x, y: posMove.y };



    }
    protected controlMove1(posMove: egret.Point): void {
        if(this.istop)
        {
           this.g_un=this.guntop;
        }
        if(!this.istop)
        {
            this.g_un=this.gun;
        }
        this.panshu = 1;
        var pos = new egret.Point((posMove.x - this.g_un.x), (posMove.y - this.g_un.y));
        this.g_un.updatePos(pos);
        var r: number = -Math.atan2(pos.x, pos.y) * 180 / Math.PI;
        this.rr = r;
        let ptFrom = { x: this.g_un.x, y: this.g_un.y };
        let ptTo = { x: 0, y: 0 };
        var angle: number = Math.atan2(pos.x, pos.y)
        ptTo = { x: ptFrom.x + Math.sin(angle) * 1000, y: ptFrom.y + Math.cos(angle) * 1000 };//1000
        let ray = new p2.Ray({ from: [ptFrom.x, ptFrom.y], to: [ptTo.x, ptTo.y], mode: p2.Ray.CLOSEST });


        var nearstBall: any;
        nearstBall = this.getRaycastProps(ptFrom.x, ptFrom.y, ptTo.x, ptTo.y);
        if (nearstBall != null) {
            this.shape1.visible = false;
            let nextPos = { x: ptFrom.x, y: ptFrom.y };
            let dis = 1000;
            let bool = false;
            while (dis > this.e + 13) {
                if (egret.Point.distance(egret.Point.create(ptFrom.x, ptFrom.y), egret.Point.create(nextPos.x, nextPos.y)) > 1100) {
                    bool = true;
                    break;
                }
                nextPos = { x: nextPos.x + ray.direction[0] * 16.666062908012332, y: nextPos.y + ray.direction[1] * 16.666062908012332 };
                dis = Math.sqrt((nextPos.x - nearstBall.m_body.position[0]) * (nextPos.x - nearstBall.m_body.position[0]) + (nextPos.y - nearstBall.m_body.position[1]) * (nextPos.y - nearstBall.m_body.position[1]));
            }
            let ptIns = { x: nextPos.x, y: nextPos.y };
            this.shape.graphics.clear();
            // this.shape.graphics.beginFill(0xf8f8ff,1);
            // this.shape.graphics.lineStyle(2, 0x00ff00);

            // //出发的线
            // this.shape.graphics.moveTo(ptFrom.x, ptFrom.y);
            // this.shape.graphics.lineTo(ptTo.x, ptTo.y);
            if (bool == false) {
                //预测碰撞位置 
                this.shape.graphics.lineStyle(3, 0xf8f8ff);//0xf8f8ff
                // this.shape.graphics.moveTo(this.gun.x, this.gun.y);
                // this.shape.graphics.lineTo(ptIns.x, ptIns.y);
                this.shape.graphics.lineStyle(1, 0xffe7be);//改变圆的颜色 
                this.shape.graphics.drawCircle(ptIns.x, ptIns.y, this.e);

                //球心联系
                this.shape.graphics.moveTo(ptIns.x, ptIns.y);
                // this.shape.graphics.lineTo(nearstBall.m_body.position[0], nearstBall.m_body.position[1]);
                //  console.log("|||||||||||||||**************" + ptIns1.x +"," +ptIns1.y + "V" + + ptIns2.x +"," +ptIns2.y );
                let rayOut = p2.vec2.clone([0, 0]);
                let rayDir = p2.vec2.clone([0, 0]);
                p2.vec2.normalize(rayDir, [ptFrom.x - ptTo.x, ptFrom.y - ptTo.y]);
                let rayNor = p2.vec2.clone([0, 0]);

                p2.vec2.normalize(rayNor, [ptIns.y - nearstBall.m_body.position[1], -ptIns.x + nearstBall.m_body.position[0]]);
                p2.vec2.reflect(rayOut, rayDir, rayNor);

                //   console.log(rayOut[0] + "{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}" + rayOut[1]);
                //垂线
                this.shape.graphics.moveTo(ptIns.x, ptIns.y);
                if (ptIns.x >= nearstBall.m_body.position[0]) {
                    this.shape.graphics.lineTo(ptIns.x + rayNor[0], ptIns.y + rayNor[1]);

                }
                else if (ptIns.x < nearstBall.m_body.position[0]) {
                    this.shape.graphics.lineTo(ptIns.x + rayNor[0], ptIns.y + rayNor[1]);
                }
                this.shape.graphics.lineStyle(1, 0xffe7be);//
                this.shape.graphics.moveTo(ptIns.x, ptIns.y);
                this.shape.graphics.lineTo(ptIns.x + rayOut[0] * 100, ptIns.y + rayOut[1] * 100);
                // this.shape.graphics.lineStyle(2, 0x0000ff);//蓝色
                let d = egret.Point.distance(egret.Point.create(ptIns.x, ptIns.y), egret.Point.create(this.g_un.x, this.g_un.y));//碰撞点 与炮的位置 之间的距离
                let bili = d / this.g_un.line.height;//线的缩放比例
                this.g_un.line.scaleY = bili;
                if (bili < 0.2) {
                    this.g_un.line.scaleX = 0.5;
                }

                //this.qiudong(ptIns.x, ptIns.y);

            }
            // this.qiudong(ptIns.x, ptIns.y);
            //反射线

            //入射线
            //  this.shape.graphics.lineStyle(2, 0x00ff00);//绿色
            // this.shape.graphics.moveTo(ptIns.x, ptIns.y);
            //  this.shape.graphics.lineTo(ptIns.x +ray.direction[0] *10,ptIns.y +ray.direction[1] *10 );
            this.shape.graphics.endFill();
            this.addChild(this.shape);


        }
        else {
            this.g_un.line.scaleY = 1;//线的缩放
            this.g_un.line.scaleX = 1;
            this.updatePoint(pos);
            this.shape.graphics.clear();
        }
        if (this.NowBullet.isRun) {
            this.shape.graphics.clear();
        }
    }
    public qiudong(X, Y) {
        //Tween动画
        var tw = egret.Tween.get(this.NowBullet);
        tw.to({ x: X, y: Y }, 1000);

    }
    protected endBackFun1() {//发射按钮的点击事件
        if (this.upgradeNumber3 == 0 || this.upgradeNumber2 == 100) {

            this.fenxiang = false;
            this.fashe2 = true;
            if (this.upgradeNumber2 == 100) {
                this.removeChild(this.bj);
                this.upgradeNumber4 = 0;
                this.upgradeNumber3 = 0;
                tanChuang=0;
                this.upgradeNumber2 = 0;
            }


        }
        else {
            if (tishi < 8) {
                /**新手指导 */
                this.Newarrow.visible = false;
                this.Newarrow1.visible = false;
                if (this.upgradeNumber4 == 1) {//新手引导
                    // if(this.upgradeNumber2 !=100){
                    // this.fenxiang = false;
                    // this.fashe2 = true;
                    this.removeChild(this.bj);
                    this.upgradeNumber4 = 0;
                    this.upgradeNumber3 = 0;
                    tanChuang=0;
                    this.upgradeNumber2 = 0;
                    // }else{
                    //      this.removeChild(this.bj);
                    //     this.upgradeNumber4 = 0;
                    //     this.upgradeNumber3 = 0;
                    //     this.upgradeNumber2 = 0;
                    // }
                }
                //          if (this.upgradeNumber4 == 6) {//新手引导
                //             this.removeChild(this.bj);
                //             this.removeChild(this.btn);
                // this.upgradeNumber4 =0;
                //             this.upgradeNumber3 = 0;
                //             this.upgradeNumber2 = 0;
                //         }
                /**新手指导箭头指示 */
                if (tishi == 3) {
                    this.addChild(this.Newjiantou);
                    this.Newjiantou.x = 360;
                    this.Newjiantou.y = 560;
                    this.Newjiantou.rotation = -30;
                    egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
                }

                if (tishi == 4) {
                    this.Newjiantou.visible = true;
                    this.Newjiantou.x = 60;
                    this.Newjiantou.y = 210;
                    egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
                }

                if (tishi == 5 || tishi == 8) {
                    this.Newjiantou.visible = true;
                    this.Newjiantou.x = 360;
                    this.Newjiantou.y = 560;
                    egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
                }
                // console.log("weqwddbwerwrw提示" + tishi);
                if (tishi == 6) {
                    this.Newjiantou.visible = true;
                    this.Newjiantou.x = 90;
                    this.Newjiantou.y = 460;
                    egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
                }

                if (tishi == 7) {
                    this.Newjiantou.visible = true;
                    this.Newjiantou.x = 360;
                    this.Newjiantou.y = 260;
                    egret.Tween.get(this.Newjiantou, { loop: true }).to({ alpha: 1 }, 300).to({ alpha: 0 }, 300);
                }

                if (this.upgradeNumber4 == 2) {
                    this.upgradeNumber2 = 0;
                    this.removeChild(this.bj);
                    var timer2: egret.Timer = new egret.Timer(500, 1);
                    //注册事件侦听器
                    timer2.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.timerComFunc22, this);
                    //开始计时
                    timer2.start();
                    this.upgradeNumber3 = 0;
                    tanChuang=0;
                    this.upgradeNumber4 = 3;
                }
            }
            console.log("-----------------------------------------------------------")

            // var shanfa = new MImage("小轮_png");
            // this.addChild(shanfa);
            // shanfa.x = 497;
            // shanfa.y = 977;
            // shanfa.scaleX = 0.5;
            // shanfa.scaleY = 0.5;
            // egret.Tween.get(shanfa).to({ scaleX: 0.7, scaleY: 0.7 }, 500).call(() => { this.removeChild(shanfa) })
            // egret.Tween.get(shanfa).to({ alpha: 0 }, 500)

        }
    }
    private timerComFunc22() {//
        this.upgradeNumber2 = 4;
        this.UpgradeTishi();

    }
    protected endBackFun(posEnd: egret.Point): void {
         var g_un;
           if(this.istop)
           {
             g_un=this.guntop;
           }
           if(!this.istop)
           {
             g_un=this.gun;
           }
        this.fenxiang = true;
        if (this.fashezhuo != null) {
            posEnd = this.fashezhuo;
        }
        var pos = new egret.Point(posEnd.x - g_un.x, posEnd.y - g_un.y);
        var angle: number = Math.atan2(pos.x, pos.y)
        var dis: number = 10000;
        var x: number = Math.ceil(Math.sin(angle) * dis);
        var y: number = Math.ceil(Math.cos(angle) * dis);
        this.vec = new egret.Point(x, y);
        // ball.velocity=[x,y]
        this.ballNum = g_un.bullet;
        // this.ballNum = 50;

        this.shape.visible = true;//与球碰撞反射线显示
        this.shape1.visible = false;
        g_un.fire();

    }
    /**开火 */
    private onFire(e: MoonEvent): void {

        this.overValue = 0;
        this.isChanger = 0;
        this.isStrike = 0;
        this.bianliang = 0;
        this.Collidetime.shuzi = 0;
        this.Collidetime.updateNum(this.Collidetime.shuzi);//开枪前将碰撞数改为0

        console.log("this.bullet333333333333333333子弹的剩余数量" + this.my_chuchun.length);
        if(this.qiehuan)
        {
            this.NowBullet.isRun=false;
        }

        if (this.NowBullet.isRun) {
            this.fashe2 = false;
            if (this.NowBullet.objkind == 301) {//普通子弹二次点击
                this.adjustment.visible=true;
                let b = this.NowBullet.runEnd();
                /**刚体球位置 */
                console.log(b.m_body.position[0]);
                console.log(b.m_body.position[1]);
                this.Collidetime.shuzi = 0;
                //  this.getPoint(b);
                this.my_ball.push(b);
                 if(this.huiheNum>=2)
                {
                    this.istop=!this.istop;
                    this.qiehuan=false;
                    this.huiheNum=0;
                }
                // if (this.boomNum >= 4) {//二次点击时判断第五次出来炸弹
                //     this.NowBullet = this.boomBullet;
                //     this.NowBullet1 = this.boomBullet;
                //    this.boomNum = 0;
                //     this.restrictNumber = 1;//限制四次后直接进入runend方法
                // }
                // this.changeColor();
            }
            if (this.NowBullet.objkind == 102 && this.restrictNumber != 1) {//爆炸子弹二次点击  && this.gun.redball.visible == false
                this.NowBullet.runEnd();
                // if (this.boomNum == 5 && this.NowBullet.isRun == false) {
                //     this.NowBullet = this.boomBullet;
                //  this.boomNum = 0;
                //     // this.changeBullet();
                //     this.changeColor();
                // }
            }
            if (this.NowBullet.objkind == 103) {//放大球
                let b = this.NowBullet.runEnd();
                //  this.getPoint(b);
                this.my_ball.push(b);

                this.changeBullet();
                this.changeColor();


            }
            if (this.NowBullet.objkind == 104) {//重力球点击
                this.NowBullet.m_body.type = 1;
                this.bianliang = 1;
                this.NowBullet.m_body.damping = 1;//阻力变1
                this.gravityTime = new egret.Timer(100, 1);
                this.gravityTime.start();//开始计时
                this.gravityTime.addEventListener(egret.TimerEvent.TIMER, this.jishi, this);//计时中事件

                if (this.NowBullet1 == null) {
                    this.changeBullet();
                    this.changeColor();
                }

            }
            if (this.NowBullet.objkind == 105) {//触发球点击


                let b = this.NowBullet.runEnd1();
                //  this.getPoint(b);
                //    this.my_ball.push(b);
                this.my_strikeBall.push(b);
                this.Striketime.chufashuzi = 3;
                if (this.propCount == 0) {
                    this.changeBullet();
                }
                this.changeColor();
            }

            this.restrictNumber = 0;
            if (this.gun.bullet <= 0 && this.NowBullet.isRun == false) {
                this.over();
            }
            // if (this.boomNum != 0) {
            //     this.NowBullet = this.fakeBullet;
            // }
            if (this.NowBullet1 != null) {
                this.changeColor1();
            }
         
        }

        else if (this.NowBullet.isRun == false && !this.sffaqiu && this.my_chuchun.length != 0 && this.fashe2) {
              this.adjustment.visible=false;
            this.huiheNum++;
           if(this.istop)
           {
             this.g_un=this.guntop;
           }
           if(!this.istop)
           {
             this.g_un=this.gun;
           }
            console.log("this.bullet子弹的剩余数量" + this.my_chuchun.length);
            SoundControl.getIns().play(MUSIC_FIRE);
            this.shape.graphics.clear();//开火按下清除反射线
            this.fashe2 = false;
            this.jiaQiuCount = 0;           //加子弹数每轮清空
            if (this.propCount > 0) {//开火前将道具数量减1
                --this.propCount;
            }
            
           this.g_un.hideLine();
            this.shu11 = 0;
            if (this.g_un.bullet > 0) {
                // if (this.NowBullet1 != null) {
                //     this.NowBullet = this.NowBullet1;
                //     // this.NowBullet1 = null;
                // }
                if (this.my_chuchun[0].objkind == 2) {
                    this.NowBullet = this.strikeBullet;
                } else if (this.my_chuchun[0].objkind == 3) {
                    this.NowBullet = this.MagnifyBullet;
                } else if (this.my_chuchun[0].objkind == 4) {
                    this.NowBullet = this.gravityBullet;;
                } else if (this.my_chuchun[0].objkind == 5) {
                    this.NowBullet = this.boomBullet;
                } else {
                    if(this.qiehuan)
                    {
                      this.NowBullet=this.Bulebullet; 
                    }
                    else
                    {
                      this.NowBullet=this.fakeBullet; 
                    }
                     
                }
                this.boomNum += 1;
                if (this.my_chuchun[0].objkind != 1) {
                    this.boomNum = 0;
                }
                this.removeChild(this.my_chuchun[0].tu)
                this.my_chuchun.splice(0, 1);
                this.NowBullet.send(this.g_un.x, this.g_un.y, this.vec.x, this.vec.y);
                /**发射角度 */

                this.g_un.updateNum(--(this.g_un.bullet));//减子弹数量              

                // if (this.gun.bullet <= 0) {
                //     var timer: egret.Timer = new egret.Timer(1200, 1);
                //     timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.destoryjinbi, this);
                //     timer.start();
                // }

                // if(this.tishi2==0){
                //     this.tishi2=1;
                //     this.upgradeNumber2=2;//新手引导
                //  	this.UpgradeTishi();//新手引导
                // }

                if (this.daojutishi == 1) {//新手引导
                    this.daojutishi = 2;
                    this.upgradeNumber2 = 6;
                    this.UpgradeTishi();
                }

                var q = 1;
                // console.log("子弹里的数量***********"+this.gun.bullet);
                //  console.log("弹夹里的数量"+this.my_chuchun.length);
                //  console.log("执行加子弹");3333333
                if (this.g_un.bullet >= this.my_chuchun.length) {//this.my_chuchun.length < 3 &&
                    //console.log("执行加子弹");
                    this.jiandan();
                }
                // if (this.gun.bullet == this.my_chuchun.length) {
                //     this.shangdan();
                // }
                this.g_un.ball.visible = false;
                this.g_un.redball.visible = false;
                this.g_un.magnify.visible = false;
                this.g_un.gravity.visible = false;
                this.g_un.strike.visible = false;
            }
            if(this.qiehuan)
                {
                    this.NowBullet.isRun=false;
                    this.fashe.visible=false;
                }

        }
    }
    // public destoryjinbi()//新手引导
    // {
    //     GameControl.GameControlSole.empty1();//清空场景里存在的金币
    // }

    /**加子弹 */
    private jiandan() {
        //     if (this.my_chuchun2.length > 0) {
        //         var a = new chun;
        //         a.tu = new MImage(lizitexiao[this.my_chuchun2[0]])
        //         a.objkind = this.my_chuchun2[0];
        //         a.tu.anchorOffsetX = a.tu.width / 2;
        //         a.tu.anchorOffsetY = a.tu.height / 2;
        //         a.tu.x = 400;//264
        //         a.tu.y = 1000;//922
        //         this.addChild(a.tu);
        //         this.my_chuchun.push(a);
        //         this.my_chuchun2.splice(0, 1);

        //     } else {
        
        var a1 = new chun;
        a1.tu = new MImage("ball_png");
        a1.objkind = 1;
        a1.tu.anchorOffsetX = a1.tu.width / 2;
        a1.tu.anchorOffsetY = a1.tu.height / 2;
        a1.tu.x = 319;//264
        a1.tu.y = 950;//922
        this.addChild(a1.tu);
        this.my_chuchun.push(a1);

        // }
        // this.shangdan();
    }
    // /**传最新位置 */
    // public position() {
    //     this.gravityResult(this.NowBullet.m_body.position[0], this.NowBullet.m_body.position[1]);

    // }
    public jishi() {
        this.NowBullet.runEnd(16, 9999);
        this.Collidetime.x = -55;
        this.Collidetime.y = -55;
    }
    /** 距离右边的距离*/
    private getRight(distance: number): number {
        return GameData.stageWidth - distance;
    }
    /** 距离右边的距离*/
    private getBottom(distance: number): number {
        return GameData.stageHeight - distance;
    }
    /** 传入宽后居中距离*/
    private getCenterX(skinWidth: number): number {
        return (GameData.stageWidth - skinWidth) >> 1;
    }
    /**设置与球的碰撞弹性 */
    public doMaterial(ball: p2.Body): void {
        var world: P2World = this.world;
        var bodys = world.p2World.bodies;
        var l: number = bodys.length;
        for (var i: number = 0; i < l; i++) {
            var body: p2.Body = bodys[i];
            if (body.userData["hit"]) {
                this.setMaterial(ball, body);
            }
        }
    }
    /** 设置刚体碰撞的弹性*/
    private setMaterial(body1: p2.Body, body2: p2.Body): void {
        var material: p2.Material = this.material;
        body1.shapes[0].material = material;
        body2.shapes[0].material = material;
        var roleAndStoneMaterial = new p2.ContactMaterial(material, material, { restitution: 0.7, friction: 0 });//弹性，摩擦力
        this.world.p2World.addContactMaterial(roleAndStoneMaterial);
    }

    /**设置属性后就可以与球碰撞 */
    private setAndBallHit(body: p2.Body): void {
        var shape = body.shapes[0];
        shape.collisionMask = 6;//010与001为0，010与110为1
    }
    /** 创建球刚体*/
    private createBall(): p2.Body {
        var world: P2World = this.world;
        var skin: MImage = this.createSkin("ball_png");
        var body: p2.Body = world.createCircleBodyShape(skin.width >> 1);
        body.userData.skin = skin;
        body.userData["ball"] = true;
        body.mass = 0;//质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
        //body.gravityScale=0;
        var shape = body.shapes[0];
        shape.collisionGroup = 2;//010与001为0，010与110为1
        // shape.collisionMask=2;
        //trace(shape.collisionGroup,shape.collisionMask)
        return body;
    }

    /** 创建皮肤*/
    private createSkin(name: string): MImage {
        var skin: NumImage = new NumImage(name);
        skin.x = -500;//避免在一出现的时候会在左上角闪现
        skin.setAnchorCenter();
        this.addChild(skin);
        return skin;
    }

    protected loopP2World(): void {
        // var bodys = this.world.p2World.bodies;
        // //traceSimple("bodys",bodys.length);
        // var l: number = bodys.length;
        // for (var i: number = 0; i < l; i++) {
        //     var body: p2.Body = bodys[i];
        //     if (body.userData && body.userData.skin) {
        //         if (body.userData["ball"]) {
        //             var vec = new Point(body.velocity[0], body.velocity[1]);
        //             var vecnum: number = Math.sqrt(vec.x * vec.x + vec.y * vec.y);
        //             if (vecnum < 1) {
        //                 console.log(vecnum);
        //                 this.setBallImpulse(body);
        //             }
        //         }
        //     }
        // }
    }
    protected loop(n: number): boolean {
        var skins: any[] = this.removeSkins;
        // traceSimple(skins.length)
        for (var i: number = 0; i < skins.length; i++) {
            var skin: NumImage = skins[i];
            skin.removeFromParent(true);
        }
        if (this.ballNum == 0) {
            this.nextLevel();
        }
        return true;
    }
    private nextLevel(): void {
        this.ballNum = this.gun.bulletMax;
        this.removeSkins.length = 0;
        this.updateNumBody();
        this.gun.initNum();
    }


    public setGameHandle(game: any) {
        this.gameHandle = game;
    }
    /**2 排行榜按钮绑定事件*/
    public paihangBtnClick() {
        let openDataContext = wx.getOpenDataContext();
        if (this.isdisplay) {
            console.log("点击后：" + this.isdisplay);
            this.bitmap.parent && this.bitmap.parent.removeChild(this.bitmap);
            this.rankingListMask.parent && this.rankingListMask.parent.removeChild(this.rankingListMask);
            this.closeBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.paihangBtnClick, this);
            this.closeBtn.parent.removeChild(this.closeBtn);
            this.isdisplay = false;
        } else {
            //处理遮罩，避免开放数据域事件影响主域。
            this.rankingListMask = new egret.Shape();
            this.rankingListMask.graphics.beginFill(0x000000, 1);
            this.rankingListMask.graphics.drawRect(0, 0, this.gameHandle.stage.width, this.gameHandle.stage.height);
            this.rankingListMask.graphics.endFill();
            this.rankingListMask.alpha = 0.5;
            this.rankingListMask.touchEnabled = true;
            this.gameHandle.addChild(this.rankingListMask);
            console.log("调取开放域");

            //简单实现，打开这关闭使用一个按钮。
            //this.gameHandle.addChild(this.gameHandle.paihang);
            //主要示例代码开始
            const bitmapdata = new egret.BitmapData(window["sharedCanvas"]);
            bitmapdata.$deleteSource = false;
            const texture = new egret.Texture();
            texture._setBitmapData(bitmapdata);
            this.bitmap = new egret.Bitmap(texture);
            this.bitmap.width = this.gameHandle.stage.stageWidth;
            this.bitmap.height = this.gameHandle.stage.stageHeight;
            this.gameHandle.addChild(this.bitmap);


            this.closeBtn = new MImage("addIcon_png");
            this.closeBtn.touchEnabled = true;
            egret.setTimeout(e => {
                this.gameHandle.addChild(this.closeBtn);
            }, this, 30);

            this.closeBtn.x = 550;
            this.closeBtn.y = 200;
            console.log("点击前：" + this.isdisplay);
            this.isdisplay = true;
            this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.paihangBtnClick, this);
            egret.startTick((timeStarmp: number) => {
                egret.WebGLUtils.deleteWebGLTexture(bitmapdata.webGLTexture);
                bitmapdata.webGLTexture = null;
                return false;
            }, this);
            //主要示例代码结束    
            this.isdisplay = true;
        }
        //发送消息
        openDataContext.postMessage({
            isDisplay: this.isdisplay,
            text: 'hello',
            year: (new Date()).getFullYear()

        });
    }

}
/**分数图标*/
class NumImage extends MImage {
    private _value: number = -1;
    private txt: TextField;
    public constructor(skinName: string = "") {
        super(skinName);
    }
    public initNum(v: number): void {
        this.txt = this.createText(0, 0);
        if (this.skinName == ICON_ADD) {
            this._value = 1;
        } else {
            this.value = v;
        }
    }
    protected createText(x: number = 0, y: number = 0, s: string = ""): TextField {
        var text: TextField = (new moon.Label).textField;
        text.x = x; text.y = y; text.text = s;
        this.addChild(text);
        return text;
    }
    set value(v: number) {
        this._value = v;
        this.txt.text = String(v);
        this.txt.textColor = 0;
        if (this.parent != null) {
            Layout.getIns().setCenterXByPanent(this.txt);
            Layout.getIns().setCenterYByPanent(this.txt);
        }
    }
    get value(): number {
        return this._value;
    }
    public get imageName(): string {
        return this.skinName;
    }
    public update(): void {
        this._value--;
        this.value = this._value;
        if (this.imageName == ICON_ADD) {
            SoundControl.getIns().play(MUSIC_ADDNUM);
        } else {
            SoundControl.getIns().play(MUSIC_HIT);
        }
    }
}
/**普通球碰撞次数显示 */
class collideTime extends moon.BasicView {
    public txtNum1: TextField;
    public shuzi: number = 0;

    protected render(): void {

        this.txtNum1 = this.createText(0, 0, "0");
        this.txtNum1.textColor = 0x000000;
        this.txtNum1.size = 30;
    }
    public updateNum(value: number): void {
        this.txtNum1.text = String(value);
        this.txtNum1.anchorOffsetX = this.txtNum1.width - 10 >> 1;
        this.txtNum1.anchorOffsetY = this.txtNum1.height - 5 >> 1;
    }
}

/**触发球碰撞次数显示 */
class strikeTime extends moon.BasicView {
    public txtNum2: TextField;

    public chufashuzi: number = 3;
    protected render(): void {

        this.txtNum2 = this.createText(0, 0, "0");
        this.txtNum2.textColor = 0x000080;
        this.txtNum2.size = 30;
    }
    public updateNum(value: number): void {
        this.txtNum2.text = String(value);
        this.txtNum2.anchorOffsetX = this.txtNum2.width - 10 >> 1;
        this.txtNum2.anchorOffsetY = this.txtNum2.height - 5 >> 1;
    }
}

/**分享按钮 */
class shareButton extends moon.BasicGameStart {
    public share: MButton;
    public initView(): void {
        var share = new MButton(new MImage("circle3_png"), new MImage("circle3_png"));
        share.anchorOffsetX = share.width >> 1;
        share.x = 15;
        share.y = -80;
        this.addChild(share);
        this.share = share;
    }

}
/**储存子弹 */
class chun extends moon.BasicView {
    public tu: MImage
    public objkind: number
}

/**枪*/
class Gun extends moon.BasicView {
    public restcishu: number = 0;//新手引导
    public lineBool: boolean;
    public gun: MImage;
    public txtNum: TextField;
    public line: MImage;
    public bulletMax: number;
    public bullet: number;
    public ball: MImage;
    public redball: MImage;
    public magnify: MImage;
    public gravity: MImage;
    public strike: MImage;
    protected render(): void {
        var gun = new MImage("gun_png");
        gun.anchorOffsetX = gun.width / 2;
        gun.anchorOffsetY = gun.height / 2;

        // this.addChild(gun);
        this.gun = gun;
        var numBg: MImage = new MImage("purpleBall_png");
        numBg.setAnchorCenter();
        //  this.addChild(numBg);

        var line: MImage = new MImage("line23_png");
        line.anchorOffsetX = line.width + 8.4 >> 1;
        this.line = line;

        this.txtNum = this.createText(20,140, "");
        this.txtNum.textColor = 0x00c4a851;
        this.bullet = this.bulletMax;
        this.updateNum(this.bullet)

        var Ball:MImage=new MImage("ball_png");
        Ball.anchorOffsetX = Ball.width / 2;
        Ball.anchorOffsetY = Ball.height / 2;
        this.addChild(Ball);
        this.ball=Ball;

        var Ball2: MImage = new MImage("redball2_png");
        Ball2.anchorOffsetX = Ball2.width / 2;
        Ball2.anchorOffsetY = Ball2.height / 2;
        this.addChild(Ball2);
        this.redball = Ball2;
        this.redball.visible = false;

        var Ball3: MImage = new MImage("purpleBall_png");
        Ball3.anchorOffsetX = Ball3.width / 2;
        Ball3.anchorOffsetY = Ball3.height / 2;
        this.addChild(Ball3);
        this.magnify = Ball3;
        this.magnify.visible = false;

        var Ball4: MImage = new MImage("zhongli_png");
        Ball4.anchorOffsetX = Ball4.width / 2;
        Ball4.anchorOffsetY = Ball4.height / 2;
        this.addChild(Ball4);
        this.gravity = Ball4;
        this.gravity.visible = false;

        var Ball5: MImage = new MImage("chu_png");
        Ball5.anchorOffsetX = Ball5.width / 2;
        Ball5.anchorOffsetY = Ball5.height / 2;
        this.addChild(Ball5);
        this.strike = Ball5;
        this.strike.visible = false;
    }
    public restart(): void {
        // if (this.restcishu == 0) {//&&egret.localStorage.getItem("xinshouyindao") == "false") {//新手引导
        //     this.bulletMax = 100;//初始子弹数量
        //     this.restcishu = 1;
        // }
        // else {
        //     // GameControl.GameControlSole.empty1();//清空所有刚体
        //     this.bulletMax = 10;//初始子弹数量
        // }//新手引导
        //  if (egret.localStorage.getItem("xinshouyindao") == "false") {
        if (tishi < 9) {

            // if (this.restcishu == 0) {//&&egret.localStorage.getItem("xinshouyindao") == "false") {//新手引导
            this.bulletMax = 100;//初始子弹数量
            console.log("初始子弹数量111111111111" + this.bulletMax);
            this.restcishu = 1;
            //  }
            // this.bulletMax = 10;
        }
        else { //if (egret.localStorage.getItem("xinshouyindao") == "true") {
            this.bulletMax = 100;
            console.log("初始子弹数量22222222222222" + this.bulletMax);
        }
        this.initNum();
    }
    public updatePos(pos: egret.Point): void {
        var r: number = -Math.atan2(pos.x, pos.y) * 180 / Math.PI;
        this.gun.rotation = r;
        this.line.rotation = r;
        this.ball.rotation = r;
        this.redball.rotation = r;
        this.magnify.rotation = r;
        this.gravity.rotation = r;
        this.strike.rotation = r;
    }
    public initNum(): void {
        this.bullet = this.bulletMax;
        this.updateNum(this.bullet)
    }
    public showLine(): void {
        this.addChildAt(this.line, 0);
        this.lineBool = true;
        Tween.get(this.line).to({ alpha: 1 }, 200);
    }
    public hideLine(): void {
        // this.line.removeFromParent();
        this.lineBool = false;

        Tween.get(this.line).to({ alpha: 0 }, 200).call(() => {
            this.line.removeFromParent();

        })
    }
    public updateNum(value: number): void {
        console.log("炮弹数量：" + value);
        this.txtNum.text = String(value);
        this.txtNum.anchorOffsetX = this.txtNum.width >> 1;
        this.txtNum.anchorOffsetY = this.txtNum.height >> 1;
    }
    public fire(): void {
        if (this.bullet >= 0) {
            // console.log("1111111111子弹剩余数量" + this.bullet);
            // this.updateNum(--this.bullet);
            Tween.get(this.gun).to({ scaleY: 0.6 }, 100).to({ scaleY: 1 }, 100);
            this.dispEvent(EVENT_FIRE);
            // setTimeout(this.fire.bind(this), 300);
            // this.ball.visible=false;
        }

    }

}
class GunTop extends moon.BasicView {
    public restcishu: number = 0;//新手引导
    public lineBool: boolean;
    public gun: MImage;
    public txtNum: TextField;
    public line: MImage;
    public bulletMax: number;
    public bullet: number;
    public ball: MImage;
    public ball_b:MImage;
    public redball: MImage;
    public magnify: MImage;
    public gravity: MImage;
    public strike: MImage;
    protected render(): void {
        var gun = new MImage("gun_png");
        gun.anchorOffsetX = gun.width / 2;
        gun.anchorOffsetY = gun.height / 2;

        this.addChild(gun);
        this.gun = gun;
        var numBg: MImage = new MImage("purpleBall_png");
        numBg.setAnchorCenter();
         this.addChild(numBg);

        var line: MImage = new MImage("line23_png");
        line.anchorOffsetX = line.width + 8.4 >> 1;
        this.line = line;
        this.txtNum = this.createText(0,-100, "");
        this.txtNum.textColor = 0x00c4a851;
        this.bullet = this.bulletMax;
        this.updateNum(this.bullet)
        var Ball:MImage=new MImage("ball_png");
        Ball.anchorOffsetX = Ball.width / 2;
        Ball.anchorOffsetY = Ball.height / 2;
        this.addChild(Ball);
        this.ball=Ball;

        var Ball2: MImage = new MImage("redball2_png");
        Ball2.anchorOffsetX = Ball2.width / 2;
        Ball2.anchorOffsetY = Ball2.height / 2;
        this.addChild(Ball2);
        this.redball = Ball2;
        this.redball.visible = false;

        var Ball3: MImage = new MImage("purpleBall_png");
        Ball3.anchorOffsetX = Ball3.width / 2;
        Ball3.anchorOffsetY = Ball3.height / 2;
        this.addChild(Ball3);
        this.magnify = Ball3;
        this.magnify.visible = false;

        var Ball4: MImage = new MImage("zhongli_png");
        Ball4.anchorOffsetX = Ball4.width / 2;
        Ball4.anchorOffsetY = Ball4.height / 2;
        this.addChild(Ball4);
        this.gravity = Ball4;
        this.gravity.visible = false;

        var Ball5: MImage = new MImage("chu_png");
        Ball5.anchorOffsetX = Ball5.width / 2;
        Ball5.anchorOffsetY = Ball5.height / 2;
        this.addChild(Ball5);
        this.strike = Ball5;
        this.strike.visible = false;
    }
    public restart(): void {
        // if (this.restcishu == 0) {//&&egret.localStorage.getItem("xinshouyindao") == "false") {//新手引导
        //     this.bulletMax = 100;//初始子弹数量
        //     this.restcishu = 1;
        // }
        // else {
        //     // GameControl.GameControlSole.empty1();//清空所有刚体
        //     this.bulletMax = 10;//初始子弹数量
        // }//新手引导
        //  if (egret.localStorage.getItem("xinshouyindao") == "false") {
        if (tishi < 9) {

            // if (this.restcishu == 0) {//&&egret.localStorage.getItem("xinshouyindao") == "false") {//新手引导
            this.bulletMax = 100;//初始子弹数量
            console.log("初始子弹数量111111111111" + this.bulletMax);
            this.restcishu = 1;
            //  }
            // this.bulletMax = 10;
        }
        else { //if (egret.localStorage.getItem("xinshouyindao") == "true") {
            this.bulletMax = 100;
            console.log("初始子弹数量22222222222222" + this.bulletMax);
        }
        this.initNum();
    }
    public updatePos(pos: egret.Point): void {
        var r: number = -Math.atan2(pos.x, pos.y) * 180 / Math.PI;
        this.gun.rotation = r;
        this.line.rotation = r;
        this.ball.rotation = r;
        this.redball.rotation = r;
        this.magnify.rotation = r;
        this.gravity.rotation = r;
        this.strike.rotation = r;
    }
    public initNum(): void {
        this.bullet = this.bulletMax;
        this.updateNum(this.bullet)
    }
    public showLine(): void {
        this.addChildAt(this.line, 0);
        this.lineBool = true;
        Tween.get(this.line).to({ alpha: 1 }, 200);
    }
    public hideLine(): void {
        // this.line.removeFromParent();
        this.lineBool = false;

        Tween.get(this.line).to({ alpha: 0 }, 200).call(() => {
            this.line.removeFromParent();

        })
    }
    public updateNum(value: number): void {
        console.log("炮弹数量：" + value);
        this.txtNum.text = String(value);
        this.txtNum.anchorOffsetX = this.txtNum.width >> 1;
        this.txtNum.anchorOffsetY = this.txtNum.height >> 1;
    }
    public fire(): void {
        if (this.bullet >= 0) {
            // console.log("1111111111子弹剩余数量" + this.bullet);
            // this.updateNum(--this.bullet);
            Tween.get(this.gun).to({ scaleY: 0.6 }, 100).to({ scaleY: 1 }, 100);
            this.dispEvent(EVENT_FIRE);
            // setTimeout(this.fire.bind(this), 300);
            // this.ball.visible=false;
        }

    }

}

class FrameAnimation extends egret.DisplayObjectContainer {
    public playAnimation(point: egret.Point): egret.MovieClip {
        var texture2mc = RES.getRes("Boom_png");
        var data2mc = RES.getRes("Boom_json");
        let mcFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data2mc, texture2mc);
        let mc: egret.MovieClip = new egret.MovieClip(mcFactory.generateMovieClipData("Boom"));
        mc.gotoAndPlay("Boom", 1);//"A" : Boom -1 ： 循环播放				
        mc.x = point.x;
        mc.y = point.y;
        //护盾
        // this.addChild();
        return mc;
    }


}